From b44a338c6d4100396434d6a982a5312d9ccc8216 Mon Sep 17 00:00:00 2001 From: Dave Gamble Date: Wed, 11 Feb 2015 11:31:35 +0000 Subject: [PATCH] Optimise out escapable array. git-svn-id: svn://svn.code.sf.net/p/cjson/code@67 e3330c51-1366-4df0-8b21-3ccf24e3d50e --- cJSON.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/cJSON.c b/cJSON.c index d8d1cca..8b5f0b2 100644 --- a/cJSON.c +++ b/cJSON.c @@ -248,22 +248,12 @@ static const char *parse_string(cJSON *item,const char *str) return ptr; } - -static int escapable[256]={ 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, - 0,0,1,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 1,0,0,0, - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, - 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0}; - /* Render the cstring provided to an escaped version that can be printed. */ static char *print_string_ptr(const char *str,printbuffer *p) { const char *ptr;char *ptr2,*out;int len=0,flag=0;unsigned char token; - ptr=str;while (*ptr) flag|=escapable[*ptr++]; + for (ptr=str;*ptr;ptr++) flag|=((*ptr>=0 && *ptr<32)||(*ptr=='\"')||(*ptr=='\\'))?1:0; if (!flag) { len=ptr-str;