1
0
mirror of https://github.com/nlohmann/json.git synced 2025-04-22 11:02:54 +03:00

avoid string in case of empty objects

This commit is contained in:
Niels Lohmann 2021-07-16 09:27:18 +02:00
parent c89e23c69b
commit b7cc47089f
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69
2 changed files with 50 additions and 44 deletions

View File

@ -1082,38 +1082,41 @@ class binary_reader
return false; return false;
} }
string_t key; if (len != 0)
if (len != std::size_t(-1))
{ {
for (std::size_t i = 0; i < len; ++i) string_t key;
if (len != std::size_t(-1))
{ {
get(); for (std::size_t i = 0; i < len; ++i)
if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
{ {
return false; get();
} if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
{
return false;
}
if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler))) if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))
{ {
return false; return false;
}
key.clear();
} }
key.clear();
} }
} else
else
{
while (get() != 0xFF)
{ {
if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key))) while (get() != 0xFF)
{ {
return false; if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
} {
return false;
}
if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler))) if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))
{ {
return false; return false;
}
key.clear();
} }
key.clear();
} }
} }

View File

@ -9298,38 +9298,41 @@ class binary_reader
return false; return false;
} }
string_t key; if (len != 0)
if (len != std::size_t(-1))
{ {
for (std::size_t i = 0; i < len; ++i) string_t key;
if (len != std::size_t(-1))
{ {
get(); for (std::size_t i = 0; i < len; ++i)
if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
{ {
return false; get();
} if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
{
return false;
}
if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler))) if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))
{ {
return false; return false;
}
key.clear();
} }
key.clear();
} }
} else
else
{
while (get() != 0xFF)
{ {
if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key))) while (get() != 0xFF)
{ {
return false; if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
} {
return false;
}
if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler))) if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))
{ {
return false; return false;
}
key.clear();
} }
key.clear();
} }
} }