From 2123c622de3a527b6173f6826bf8ceb21ed840fd Mon Sep 17 00:00:00 2001 From: Mark Pulford Date: Tue, 10 May 2011 20:11:05 +0930 Subject: Remove whitespace from generated JSON output Remove excess whitespace to reduce output size and increase encode performance. Suggested by: Zhang "agentzh" Yichun --- lua_cjson.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lua_cjson.c') diff --git a/lua_cjson.c b/lua_cjson.c index fa2d6a7..63b3d06 100644 --- a/lua_cjson.c +++ b/lua_cjson.c @@ -500,12 +500,12 @@ static void json_append_array(lua_State *l, json_config_t *cfg, strbuf_t *json, json_encode_descend(l, cfg); - strbuf_append_mem(json, "[ ", 2); + strbuf_append_char(json, '['); comma = 0; for (i = 1; i <= array_length; i++) { if (comma) - strbuf_append_mem(json, ", ", 2); + strbuf_append_char(json, ','); else comma = 1; @@ -514,7 +514,7 @@ static void json_append_array(lua_State *l, json_config_t *cfg, strbuf_t *json, lua_pop(l, 1); } - strbuf_append_mem(json, " ]", 2); + strbuf_append_char(json, ']'); cfg->current_depth--; } @@ -538,14 +538,14 @@ static void json_append_object(lua_State *l, json_config_t *cfg, json_encode_descend(l, cfg); /* Object */ - strbuf_append_mem(json, "{ ", 2); + strbuf_append_char(json, '{'); lua_pushnil(l); /* table, startkey */ comma = 0; while (lua_next(l, -2) != 0) { if (comma) - strbuf_append_mem(json, ", ", 2); + strbuf_append_char(json, ','); else comma = 1; @@ -554,10 +554,10 @@ static void json_append_object(lua_State *l, json_config_t *cfg, if (keytype == LUA_TNUMBER) { strbuf_append_char(json, '"'); json_append_number(l, json, -2, cfg->encode_refuse_badnum); - strbuf_append_mem(json, "\": ", 3); + strbuf_append_mem(json, "\":", 2); } else if (keytype == LUA_TSTRING) { json_append_string(l, json, -2); - strbuf_append_mem(json, ": ", 2); + strbuf_append_char(json, ':'); } else { json_encode_exception(l, -2, "table key must be a number or string"); @@ -570,7 +570,7 @@ static void json_append_object(lua_State *l, json_config_t *cfg, /* table, key */ } - strbuf_append_mem(json, " }", 2); + strbuf_append_char(json, '}'); cfg->current_depth--; } -- cgit v1.2.3-55-g6feb