diff --git a/ChangeLog b/ChangeLog index 9ee2c08c..c83d58bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2021-01-16 Jay Berkenbilt + * 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 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"; QPDF's public API. + + + Re-implement QPDFNameTreeObjectHelper + and QPDFNumberTreeObjectHelper to be + more efficient, and add an iterator-based API. + +