From ae1bb27ddae9287a8d96047e94196e41b2daab3f Mon Sep 17 00:00:00 2001 From: Xie Han <63350856@qq.com> Date: Tue, 30 Jan 2024 23:06:03 +0800 Subject: [PATCH] Optimize estimating JSON string length. --- src/util/json_parser.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/util/json_parser.c b/src/util/json_parser.c index 110b2e71..901cd2e2 100644 --- a/src/util/json_parser.c +++ b/src/util/json_parser.c @@ -76,18 +76,16 @@ static int __json_string_length(const char *cursor) while (*cursor != '\"') { - if ((unsigned char)*cursor < ' ') + if (*cursor == '\\') + { + cursor++; + if (*cursor == '\0') + return -2; + } + else if ((unsigned char)*cursor < 0x20) return -2; cursor++; - if (cursor[-1] == '\\') - { - if (*cursor == '\0') - return -2; - - cursor++; - } - len++; }