Use Json::StaticString for field names

Clean up some code relating to unknown fields and avoid
allocate/copy/free cycles for Json objects containing
serialized field names.
This commit is contained in:
JoelKatz
2018-08-07 13:30:52 -07:00
committed by Nik Bougalis
parent 8c1123edc6
commit b6363289bf
4 changed files with 44 additions and 49 deletions

View File

@@ -658,17 +658,10 @@ Json::Value STObject::getJson (int options) const
{
Json::Value ret (Json::objectValue);
// TODO(tom): this variable is never changed...?
int index = 1;
for (auto const& elem : v_)
{
if (elem->getSType () != STI_NOTPRESENT)
{
auto const& n = elem->getFName ();
auto key = n.hasName () ? std::string(n.getJsonName ()) :
std::to_string (index);
ret[key] = elem->getJson (options);
}
ret [elem->getFName().getJsonName()] = elem->getJson (options);
}
return ret;
}