From 9e03dc54cc50c173f75375e76b31607a03c3f4a4 Mon Sep 17 00:00:00 2001 From: m-holger Date: Mon, 7 Oct 2024 17:29:35 +0100 Subject: [PATCH] Add new method Objects::swap --- include/qpdf/QPDF.hh | 2 +- libqpdf/QPDF.cc | 8 +++++++- libqpdf/QPDF_objects.cc | 8 ++++---- libqpdf/qpdf/QPDF_objects.hh | 2 ++ 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index 5729d3bf..9e638fa8 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -391,7 +391,7 @@ class QPDF void replaceObject(int objid, int generation, QPDFObjectHandle); // Swap two objects given by ID. Prior to qpdf 10.2.1, existing QPDFObjectHandle instances that - // reference them objects not notice the swap, but this was fixed in 10.2.1. + // reference the objects did not notice the swap, but this was fixed in 10.2.1. QPDF_DLL void swapObjects(QPDFObjGen const& og1, QPDFObjGen const& og2); QPDF_DLL diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index e7a76b80..beab50ee 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -882,7 +882,13 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign) void QPDF::swapObjects(int objid1, int generation1, int objid2, int generation2) { - swapObjects(QPDFObjGen(objid1, generation1), QPDFObjGen(objid2, generation2)); + m->objects.swap(QPDFObjGen(objid1, generation1), QPDFObjGen(objid2, generation2)); +} + +void +QPDF::swapObjects(QPDFObjGen const& og1, QPDFObjGen const& og2) +{ + m->objects.swap(og1, og2); } unsigned long long diff --git a/libqpdf/QPDF_objects.cc b/libqpdf/QPDF_objects.cc index 920517db..6857b2eb 100644 --- a/libqpdf/QPDF_objects.cc +++ b/libqpdf/QPDF_objects.cc @@ -1779,12 +1779,12 @@ Objects::erase(QPDFObjGen og) } void -QPDF::swapObjects(QPDFObjGen const& og1, QPDFObjGen const& og2) +Objects::swap(QPDFObjGen og1, QPDFObjGen og2) { // Force objects to be read from the input source if needed, then swap them in the cache. - m->objects.resolve(og1); - m->objects.resolve(og2); - m->objects.obj_cache[og1].object->swapWith(m->objects.obj_cache[og2].object); + resolve(og1); + resolve(og2); + obj_cache[og1].object->swapWith(obj_cache[og2].object); } size_t diff --git a/libqpdf/qpdf/QPDF_objects.hh b/libqpdf/qpdf/QPDF_objects.hh index ad12f9c4..43e3048a 100644 --- a/libqpdf/qpdf/QPDF_objects.hh +++ b/libqpdf/qpdf/QPDF_objects.hh @@ -445,6 +445,8 @@ class QPDF::Objects void replace(QPDFObjGen og, QPDFObjectHandle oh); + void swap(QPDFObjGen og1, QPDFObjGen og2); + std::map obj_cache; QPDFObjectHandle readObjectInStream(std::shared_ptr& input, int obj);