performance optimization

This commit is contained in:
qiwei 2024-10-06 01:57:15 +08:00
parent 5defb4ed1a
commit 58a0d130c2

View File

@ -869,6 +869,7 @@ public:
bool rejectDupKeys_; bool rejectDupKeys_;
bool allowSpecialFloats_; bool allowSpecialFloats_;
bool skipBom_; bool skipBom_;
bool skipEscapeString_;
size_t stackLimit_; size_t stackLimit_;
}; // OurFeatures }; // OurFeatures
@ -1454,8 +1455,9 @@ bool OurReader::readObject(Token& token) {
return true; return true;
name.clear(); name.clear();
if (tokenName.type_ == tokenString) { if (tokenName.type_ == tokenString) {
if (!decodeString(tokenName, name)) name = String(tokenName.start_ + 1, tokenName.end_-1);
return recoverFromError(tokenObjectEnd); //if (!decodeString(tokenName, name))
// return recoverFromError(tokenObjectEnd);
} else if (tokenName.type_ == tokenNumber && features_.allowNumericKeys_) { } else if (tokenName.type_ == tokenNumber && features_.allowNumericKeys_) {
Value numberName; Value numberName;
if (!decodeNumber(tokenName, numberName)) if (!decodeNumber(tokenName, numberName))
@ -1669,6 +1671,10 @@ bool OurReader::decodeString(Token& token, String& decoded) {
decoded.reserve(static_cast<size_t>(token.end_ - token.start_ - 2)); decoded.reserve(static_cast<size_t>(token.end_ - token.start_ - 2));
Location current = token.start_ + 1; // skip '"' Location current = token.start_ + 1; // skip '"'
Location end = token.end_ - 1; // do not include '"' Location end = token.end_ - 1; // do not include '"'
if (features_.skipEscapeString_) {
decoded = String(current, end);
return true;
}
while (current != end) { while (current != end) {
Char c = *current++; Char c = *current++;
if (c == '"') if (c == '"')
@ -1897,6 +1903,7 @@ CharReader* CharReaderBuilder::newCharReader() const {
features.rejectDupKeys_ = settings_["rejectDupKeys"].asBool(); features.rejectDupKeys_ = settings_["rejectDupKeys"].asBool();
features.allowSpecialFloats_ = settings_["allowSpecialFloats"].asBool(); features.allowSpecialFloats_ = settings_["allowSpecialFloats"].asBool();
features.skipBom_ = settings_["skipBom"].asBool(); features.skipBom_ = settings_["skipBom"].asBool();
features.skipEscapeString_ = settings_["skipEscapeString"].asBool();
return new OurCharReader(collectComments, features); return new OurCharReader(collectComments, features);
} }