Bug 1600963 - build fields directly in the returned array; r=mccr8

This change means fewer temporary objects, particularly `nsCString` objects.

Depends on D55688

Differential Revision: https://phabricator.services.mozilla.com/D55689

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nathan Froyd 2019-12-03 17:37:43 +00:00
Родитель 03bf239fb9
Коммит 655d31fb03
1 изменённых файлов: 7 добавлений и 8 удалений

Просмотреть файл

@ -162,21 +162,20 @@ static nsTArray<typename T::KeyVal> GetJSONKeys(const Json::Value* aInput) {
int size = T::eMax + 1;
nsTArray<typename T::KeyVal> fields;
for (int i = 0; i != size; i++) {
typename T::KeyVal field;
// field.valueWasSerialized returns if the field was found in the
typename T::KeyVal* field = fields.AppendElement();
// field->valueWasSerialized returns if the field was found in the
// deserialized code. This simplifies the consumers from having to check
// length.
field.valueWasSerialized = false;
field.key = static_cast<typename T::SerializableKeys>(i);
const std::string key = std::to_string(field.key);
field->valueWasSerialized = false;
field->key = static_cast<typename T::SerializableKeys>(i);
const std::string key = std::to_string(field->key);
if (aInput->isMember(key)) {
const Json::Value& val = (*aInput)[key];
if (val.isString()) {
field.value.Append(nsDependentCString(val.asCString()));
field.valueWasSerialized = true;
field->value.Append(nsDependentCString(val.asCString()));
field->valueWasSerialized = true;
}
}
fields.AppendElement(field);
}
return fields;
}