Commit ba814703fbfc99c99d24c8873ae3356b2623dc69

Authored by Jay Berkenbilt
1 parent 5f070841

Use QPDFNameTreeObjectHelper's iterator directly

ChangeLog
1 1 2021-01-16 Jay Berkenbilt <ejb@ql.org>
2 2  
  3 + * Re-implement QPDFNameTreeObjectHelper and
  4 + QPDFNumberTreeObjectHelper to be much more efficient and to have
  5 + an iterator-based API in addition to the existing one. This makes
  6 + it possible to use "range-for" loops over these helpers and to
  7 + iterate through name and number trees without creating a map
  8 + containing all the keys and values, which is slow and potentially
  9 + consumes a lot of memory.
  10 +
3 11 * Add warn() to QPDF's public API.
4 12  
5 13 2021-01-11 Jay Berkenbilt <ejb@ql.org>
... ...
include/qpdf/QPDFNameTreeObjectHelper.hh
... ... @@ -53,7 +53,7 @@ class QPDFNameTreeObjectHelper: public QPDFObjectHelper
53 53 bool hasName(std::string const& utf8);
54 54  
55 55 // Find an object by name. If found, returns true and initializes
56   - // oh.
  56 + // oh. See also find().
57 57 QPDF_DLL
58 58 bool findObject(std::string const& utf8, QPDFObjectHandle& oh);
59 59  
... ...
include/qpdf/QPDFNumberTreeObjectHelper.hh
... ... @@ -60,7 +60,7 @@ class QPDFNumberTreeObjectHelper: public QPDFObjectHelper
60 60 bool hasIndex(numtree_number idx);
61 61  
62 62 // Find an object with a specific index. If found, returns true
63   - // and initializes oh.
  63 + // and initializes oh. See also find().
64 64 QPDF_DLL
65 65 bool findObject(numtree_number idx, QPDFObjectHandle& oh);
66 66 // Find the object at the index or, if not found, the object whose
... ... @@ -70,7 +70,8 @@ class QPDFNumberTreeObjectHelper: public QPDFObjectHelper
70 70 // offset to the difference between the requested index and the
71 71 // actual index. For example, if a number tree has values for 3
72 72 // and 6 and idx is 5, this method would return true, initialize
73   - // oh to the value with index 3, and set offset to 2 (5 - 3).
  73 + // oh to the value with index 3, and set offset to 2 (5 - 3). See
  74 + // also find().
74 75 QPDF_DLL
75 76 bool findObjectAtOrBelow(numtree_number idx, QPDFObjectHandle& oh,
76 77 numtree_number& offset);
... ...
libqpdf/QPDF.cc
... ... @@ -3011,8 +3011,7 @@ QPDF::findAttachmentStreams()
3011 3011 return;
3012 3012 }
3013 3013 QPDFNameTreeObjectHelper ef_tree(embedded_files);
3014   - auto ef_tree_map = ef_tree.getAsMap();
3015   - for (auto& i: ef_tree_map)
  3014 + for (auto i: ef_tree)
3016 3015 {
3017 3016 QPDFObjectHandle item = i.second;
3018 3017 if (item.isDictionary() &&
... ...
manual/qpdf-manual.xml
... ... @@ -4833,6 +4833,13 @@ print &quot;\n&quot;;
4833 4833 <classname>QPDF</classname>'s public API.
4834 4834 </para>
4835 4835 </listitem>
  4836 + <listitem>
  4837 + <para>
  4838 + Re-implement <classname>QPDFNameTreeObjectHelper</classname>
  4839 + and <classname>QPDFNumberTreeObjectHelper</classname> to be
  4840 + more efficient, and add an iterator-based API.
  4841 + </para>
  4842 + </listitem>
4836 4843 </itemizedlist>
4837 4844 </listitem>
4838 4845 </itemizedlist>
... ...