From ae2d623929c280f1d2411787bf4e41d5d91a4f3a Mon Sep 17 00:00:00 2001 From: m-holger Date: Thu, 18 May 2023 18:05:59 +0100 Subject: [PATCH] Use QPDFObjGen::set in QPDF::updateObjectMaps --- include/qpdf/QPDF.hh | 2 +- libqpdf/QPDF_optimization.cc | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index 88dadcdb..955f9c17 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -1645,7 +1645,7 @@ class QPDF ObjUser const& ou, QPDFObjectHandle oh, std::function skip_stream_parameters, - std::set& visited, + QPDFObjGen::set& visited, bool top); void filterCompressedObjects(std::map const& object_stream_data); diff --git a/libqpdf/QPDF_optimization.cc b/libqpdf/QPDF_optimization.cc index 41204fbd..0c534432 100644 --- a/libqpdf/QPDF_optimization.cc +++ b/libqpdf/QPDF_optimization.cc @@ -284,7 +284,7 @@ QPDF::updateObjectMaps( QPDFObjectHandle oh, std::function skip_stream_parameters) { - std::set visited; + QPDFObjGen::set visited; updateObjectMapsInternal(ou, oh, skip_stream_parameters, visited, true); } @@ -293,7 +293,7 @@ QPDF::updateObjectMapsInternal( ObjUser const& ou, QPDFObjectHandle oh, std::function skip_stream_parameters, - std::set& visited, + QPDFObjGen::set& visited, bool top) { // Traverse the object tree from this point taking care to avoid @@ -310,13 +310,12 @@ QPDF::updateObjectMapsInternal( if (oh.isIndirect()) { QPDFObjGen og(oh.getObjGen()); - if (visited.count(og)) { + if (!visited.add(og)) { QTC::TC("qpdf", "QPDF opt loop detected"); return; } this->m->obj_user_to_objects[ou].insert(og); this->m->object_to_obj_users[og].insert(ou); - visited.insert(og); } if (oh.isArray()) {