From 575724a15fe46d7392b419a8afbdabd00eed3b7c Mon Sep 17 00:00:00 2001 From: Dave Gamble Date: Mon, 9 Feb 2015 17:25:55 +0000 Subject: [PATCH] optimises for number/string print git-svn-id: svn://svn.code.sf.net/p/cjson/code@59 e3330c51-1366-4df0-8b21-3ccf24e3d50e --- cJSON.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/cJSON.c b/cJSON.c index 31c43dd..0ce5f08 100644 --- a/cJSON.c +++ b/cJSON.c @@ -122,7 +122,16 @@ static char *print_number(cJSON *item) if (fabs(((double)item->valueint)-d)<=DBL_EPSILON && d<=INT_MAX && d>=INT_MIN) { str=(char*)cJSON_malloc(21); /* 2^64+1 can be represented in 21 chars. */ - if (str) sprintf(str,"%d",item->valueint); + if (str) + { + int i,j,t; + + if (d<0) t=-d; else t=d; + for (i=0;t>0;t/=10) str[i++]='0'+(t%10); + if (d<0) str[i++]='-'; + str[i--]=0; + for (j=0;j