aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2021-01-16 18:11:35 +0100
committerJay Berkenbilt <ejb@ql.org>2021-01-24 09:25:11 +0100
commitba814703fbfc99c99d24c8873ae3356b2623dc69 (patch)
tree8e5f3f9cb708700a6d596f3d7e9a6498de54eebe
parent5f0708418a0a9cbacc033f52efc11c759120fd09 (diff)
downloadqpdf-ba814703fbfc99c99d24c8873ae3356b2623dc69.tar.zst
Use QPDFNameTreeObjectHelper's iterator directly
-rw-r--r--ChangeLog8
-rw-r--r--include/qpdf/QPDFNameTreeObjectHelper.hh2
-rw-r--r--include/qpdf/QPDFNumberTreeObjectHelper.hh5
-rw-r--r--libqpdf/QPDF.cc3
-rw-r--r--manual/qpdf-manual.xml7
5 files changed, 20 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 9ee2c08c..c83d58bd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2021-01-16 Jay Berkenbilt <ejb@ql.org>
+ * Re-implement QPDFNameTreeObjectHelper and
+ QPDFNumberTreeObjectHelper to be much more efficient and to have
+ an iterator-based API in addition to the existing one. This makes
+ it possible to use "range-for" loops over these helpers and to
+ iterate through name and number trees without creating a map
+ containing all the keys and values, which is slow and potentially
+ consumes a lot of memory.
+
* Add warn() to QPDF's public API.
2021-01-11 Jay Berkenbilt <ejb@ql.org>
diff --git a/include/qpdf/QPDFNameTreeObjectHelper.hh b/include/qpdf/QPDFNameTreeObjectHelper.hh
index f94d34cf..e5bb2893 100644
--- a/include/qpdf/QPDFNameTreeObjectHelper.hh
+++ b/include/qpdf/QPDFNameTreeObjectHelper.hh
@@ -53,7 +53,7 @@ class QPDFNameTreeObjectHelper: public QPDFObjectHelper
bool hasName(std::string const& utf8);
// Find an object by name. If found, returns true and initializes
- // oh.
+ // oh. See also find().
QPDF_DLL
bool findObject(std::string const& utf8, QPDFObjectHandle& oh);
diff --git a/include/qpdf/QPDFNumberTreeObjectHelper.hh b/include/qpdf/QPDFNumberTreeObjectHelper.hh
index 393e8dba..d4e93690 100644
--- a/include/qpdf/QPDFNumberTreeObjectHelper.hh
+++ b/include/qpdf/QPDFNumberTreeObjectHelper.hh
@@ -60,7 +60,7 @@ class QPDFNumberTreeObjectHelper: public QPDFObjectHelper
bool hasIndex(numtree_number idx);
// Find an object with a specific index. If found, returns true
- // and initializes oh.
+ // and initializes oh. See also find().
QPDF_DLL
bool findObject(numtree_number idx, QPDFObjectHandle& oh);
// Find the object at the index or, if not found, the object whose
@@ -70,7 +70,8 @@ class QPDFNumberTreeObjectHelper: public QPDFObjectHelper
// offset to the difference between the requested index and the
// actual index. For example, if a number tree has values for 3
// and 6 and idx is 5, this method would return true, initialize
- // oh to the value with index 3, and set offset to 2 (5 - 3).
+ // oh to the value with index 3, and set offset to 2 (5 - 3). See
+ // also find().
QPDF_DLL
bool findObjectAtOrBelow(numtree_number idx, QPDFObjectHandle& oh,
numtree_number& offset);
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc
index 647e94c2..5b590525 100644
--- a/libqpdf/QPDF.cc
+++ b/libqpdf/QPDF.cc
@@ -3011,8 +3011,7 @@ QPDF::findAttachmentStreams()
return;
}
QPDFNameTreeObjectHelper ef_tree(embedded_files);
- auto ef_tree_map = ef_tree.getAsMap();
- for (auto& i: ef_tree_map)
+ for (auto i: ef_tree)
{
QPDFObjectHandle item = i.second;
if (item.isDictionary() &&
diff --git a/manual/qpdf-manual.xml b/manual/qpdf-manual.xml
index e770c3c4..a969ce32 100644
--- a/manual/qpdf-manual.xml
+++ b/manual/qpdf-manual.xml
@@ -4833,6 +4833,13 @@ print "\n";
<classname>QPDF</classname>'s public API.
</para>
</listitem>
+ <listitem>
+ <para>
+ Re-implement <classname>QPDFNameTreeObjectHelper</classname>
+ and <classname>QPDFNumberTreeObjectHelper</classname> to be
+ more efficient, and add an iterator-based API.
+ </para>
+ </listitem>
</itemizedlist>
</listitem>
</itemizedlist>