Commit 1787d85096c47bb3986b529af2a118793179a040

Authored by m-holger
Committed by Jay Berkenbilt
1 parent dce43d4f

Refactor JSON::addDictionaryMember

Showing 1 changed file with 4 additions and 8 deletions
libqpdf/JSON.cc
... ... @@ -266,17 +266,13 @@ JSON::makeDictionary()
266 266 JSON
267 267 JSON::addDictionaryMember(std::string const& key, JSON const& val)
268 268 {
269   - JSON_dictionary* obj = dynamic_cast<JSON_dictionary*>(this->m->value.get());
270   - if (nullptr == obj) {
  269 + if (auto* obj = dynamic_cast<JSON_dictionary*>(this->m->value.get())) {
  270 + return obj->members[encode_string(key)] =
  271 + val.m->value ? val.m->value : std::make_shared<JSON_null>();
  272 + } else {
271 273 throw std::runtime_error(
272 274 "JSON::addDictionaryMember called on non-dictionary");
273 275 }
274   - if (val.m->value.get()) {
275   - obj->members[encode_string(key)] = val.m->value;
276   - } else {
277   - obj->members[encode_string(key)] = std::make_shared<JSON_null>();
278   - }
279   - return obj->members[encode_string(key)];
280 276 }
281 277  
282 278 bool
... ...