From 8ed3e8c79b5cbccfeccee865e555b68025ee2c1f Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Mon, 25 Jan 2021 08:05:43 -0500 Subject: NNTree: rework iterators to be more memory efficient Keep a std::pair internal to the iterators so that operator* can return a reference and operator-> can work, and each can work without copying pairs of objects around. --- libqpdf/qpdf/NNTree.hh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'libqpdf/qpdf') diff --git a/libqpdf/qpdf/NNTree.hh b/libqpdf/qpdf/NNTree.hh index e8360df1..4a843a73 100644 --- a/libqpdf/qpdf/NNTree.hh +++ b/libqpdf/qpdf/NNTree.hh @@ -6,6 +6,7 @@ #include #include +#include class NNTreeDetails { @@ -18,9 +19,6 @@ class NNTreeDetails class NNTreeImpl; class NNTreeIterator: public std::iterator< std::bidirectional_iterator_tag, - std::pair, - void, - std::pair*, std::pair> { friend class NNTreeImpl; @@ -41,6 +39,7 @@ class NNTreeIterator: public std::iterator< return t; } reference operator*(); + pointer operator->(); bool operator==(NNTreeIterator const& other) const; bool operator!=(NNTreeIterator const& other) const { @@ -63,6 +62,7 @@ class NNTreeIterator: public std::iterator< // ABI: for qpdf 11, make qpdf a reference NNTreeIterator(NNTreeImpl& impl); + void updateIValue(bool allow_invalid = true); bool deepen(QPDFObjectHandle node, bool first, bool allow_empty); void setItemNumber(QPDFObjectHandle const& node, int); void addPathElement(QPDFObjectHandle const& node, int kid_number); @@ -79,6 +79,7 @@ class NNTreeIterator: public std::iterator< std::list path; QPDFObjectHandle node; int item_number; + value_type ivalue; }; class NNTreeImpl -- cgit v1.2.3-70-g09d2