Commit f8b548c89c8b89a46b7f5253e47f9544589bddf4

Authored by m-holger
1 parent 8f0073ed

Refactor `NNTreeImpl::insert` and `NNTreeIterator::remove`: replace `getKey` wit…

…h subscript operator, streamline `repair` with `Dictionary` initializer, and remove redundant semicolon.
libqpdf/NNTree.cc
... ... @@ -662,16 +662,15 @@ NNTreeImpl::compareKeyKid(QPDFObjectHandle const& key, Array const& kids, int id
662 662 void
663 663 NNTreeImpl::repair()
664 664 {
665   - auto new_node = QPDFObjectHandle::newDictionary();
666   - new_node.replaceKey(itemsKey(), Array::empty());
  665 + auto new_node = Dictionary({{itemsKey(), Array::empty()}});
667 666 NNTreeImpl repl(qpdf, new_node, key_type, value_valid, false);
668 667 for (auto const& [key, value]: *this) {
669 668 if (key && value) {
670 669 repl.insert(key, value);
671 670 }
672 671 }
673   - oh.replaceKey("/Kids", new_node.getKey("/Kids"));
674   - oh.replaceKey(itemsKey(), new_node.getKey(itemsKey()));
  672 + oh.replaceKey("/Kids", new_node["/Kids"]);
  673 + oh.replaceKey(itemsKey(), new_node[itemsKey()]);
675 674 }
676 675  
677 676 NNTreeImpl::iterator
... ... @@ -757,10 +756,7 @@ NNTreeImpl::iterator
757 756 NNTreeImpl::insertFirst(QPDFObjectHandle const& key, QPDFObjectHandle const& value)
758 757 {
759 758 auto iter = begin();
760   - Array items;
761   - if (iter.node.isDictionary()) {
762   - items = iter.node.getKey(itemsKey());
763   - }
  759 + Array items = iter.node[items_key];
764 760 if (!items) {
765 761 error(oh, "unable to find a valid items node");
766 762 }
... ... @@ -785,7 +781,7 @@ NNTreeImpl::insert(QPDFObjectHandle const& key, QPDFObjectHandle const& value)
785 781 if (!iter.valid()) {
786 782 return insertFirst(key, value);
787 783 } else if (compareKeys(key, iter->first) == 0) {
788   - Array items = iter.node.getKey(itemsKey());
  784 + Array items = iter.node[itemsKey()];
789 785 items.set(iter.item_number + 1, value);
790 786 iter.updateIValue();
791 787 } else {
... ...
libqpdf/qpdf/NNTree.hh
... ... @@ -128,12 +128,12 @@ class NNTreeImpl final
128 128  
129 129 NNTreeImpl(
130 130 QPDF& qpdf,
131   - QPDFObjectHandle& oh,
  131 + QPDFObjectHandle oh,
132 132 qpdf_object_type_e key_type,
133 133 std::function<bool(QPDFObjectHandle const&)> value_validator,
134 134 bool auto_repair) :
135 135 qpdf(qpdf),
136   - oh(oh),
  136 + oh(std::move(oh)),
137 137 key_type(key_type),
138 138 items_key(key_type == ::ot_string ? "/Names" : "/Nums"),
139 139 value_valid(value_validator),
... ...