From 58a0d130c2953c2ed760d9bdeee3c19ab896582d Mon Sep 17 00:00:00 2001 From: qiwei Date: Sun, 6 Oct 2024 01:57:15 +0800 Subject: [PATCH 1/3] performance optimization --- src/lib_json/json_reader.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index a6a3f4e30..8202833cc 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -869,6 +869,7 @@ class OurFeatures { bool rejectDupKeys_; bool allowSpecialFloats_; bool skipBom_; + bool skipEscapeString_; size_t stackLimit_; }; // OurFeatures @@ -1454,8 +1455,9 @@ bool OurReader::readObject(Token& token) { return true; name.clear(); if (tokenName.type_ == tokenString) { - if (!decodeString(tokenName, name)) - return recoverFromError(tokenObjectEnd); + name = String(tokenName.start_ + 1, tokenName.end_-1); + //if (!decodeString(tokenName, name)) + // return recoverFromError(tokenObjectEnd); } else if (tokenName.type_ == tokenNumber && features_.allowNumericKeys_) { Value numberName; if (!decodeNumber(tokenName, numberName)) @@ -1669,6 +1671,10 @@ bool OurReader::decodeString(Token& token, String& decoded) { decoded.reserve(static_cast(token.end_ - token.start_ - 2)); Location current = token.start_ + 1; // skip '"' Location end = token.end_ - 1; // do not include '"' + if (features_.skipEscapeString_) { + decoded = String(current, end); + return true; + } while (current != end) { Char c = *current++; if (c == '"') @@ -1897,6 +1903,7 @@ CharReader* CharReaderBuilder::newCharReader() const { features.rejectDupKeys_ = settings_["rejectDupKeys"].asBool(); features.allowSpecialFloats_ = settings_["allowSpecialFloats"].asBool(); features.skipBom_ = settings_["skipBom"].asBool(); + features.skipEscapeString_ = settings_["skipEscapeString"].asBool(); return new OurCharReader(collectComments, features); } From 30ce8e1fa7840e0a2a19e619a8ba058c040c1249 Mon Sep 17 00:00:00 2001 From: qiwei Date: Sun, 6 Oct 2024 13:30:02 +0800 Subject: [PATCH 2/3] clang format --- src/lib_json/json_reader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index c9a55cf2a..2b554c89b 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -1653,8 +1653,8 @@ bool OurReader::decodeString(Token& token, String& decoded) { Location current = token.start_ + 1; // skip '"' Location end = token.end_ - 1; // do not include '"' if (features_.skipEscapeString_) { - decoded = String(current, end); - return true; + decoded = String(current, end); + return true; } while (current != end) { Char c = *current++; From 5d634a519d4a35946c2a96a14ce0f6b2fec6da07 Mon Sep 17 00:00:00 2001 From: qiwei Date: Sun, 6 Oct 2024 15:40:01 +0800 Subject: [PATCH 3/3] clang-format --- src/lib_json/json_reader.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 2b554c89b..0aef0c235 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -1439,9 +1439,10 @@ bool OurReader::readObject(Token& token) { return true; name.clear(); if (tokenName.type_ == tokenString) { - name = String(tokenName.start_ + 1, tokenName.end_-1); - //if (!decodeString(tokenName, name)) - // return recoverFromError(tokenObjectEnd); + name = String(tokenName.start_ + 1, tokenName.end_ - 1); + /*if (!decodeString(tokenName, name)) + return recoverFromError(tokenObjectEnd); + */ } else if (tokenName.type_ == tokenNumber && features_.allowNumericKeys_) { Value numberName; if (!decodeNumber(tokenName, numberName)) @@ -1901,7 +1902,7 @@ CharReader* CharReaderBuilder::newCharReader() const { features.rejectDupKeys_ = settings_["rejectDupKeys"].asBool(); features.allowSpecialFloats_ = settings_["allowSpecialFloats"].asBool(); features.skipBom_ = settings_["skipBom"].asBool(); - features.skipEscapeString_ = settings_["skipEscapeString"].asBool(); + features.skipEscapeString_ = settings_["skipEscapeString"].asBool(); return new OurCharReader(collectComments, features); }