From 38afdcea7b08226aa6cc12a8fcda93a6f35a0a18 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 2 Apr 2020 17:52:21 -0400 Subject: Add QPDFObjectHandle::unsafeShallowCopy --- include/qpdf/QPDFObjectHandle.hh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh index 38f29106..dcb7de35 100644 --- a/include/qpdf/QPDFObjectHandle.hh +++ b/include/qpdf/QPDFObjectHandle.hh @@ -670,10 +670,24 @@ class QPDFObjectHandle // traverse across indirect object boundaries. That means that, // for dictionaries and arrays, any keys or items that were // indirect objects will still be indirect objects that point to - // the same place. + // the same place. In the strictest sense, this is not a shallow + // copy because it recursively descends arrays and dictionaries; + // it just doesn't cross over indirect objects. See also + // unsafeShallowCopy(). QPDF_DLL QPDFObjectHandle shallowCopy(); + // Create a true shallow copy of an array or dictionary, just + // copying the immediate items (array) or keys (dictionary). This + // is "unsafe" because, if you *modify* any of the items in the + // copy, you are modifying the original, which is almost never + // what you want. However, if your intention is merely to + // *replace* top-level items or keys and not to modify lower-level + // items in the copy, this method is much faster than + // shallowCopy(). + QPDF_DLL + QPDFObjectHandle unsafeShallowCopy(); + // Mutator methods. Use with caution. // Recursively copy this object, making it direct. Throws an @@ -1053,7 +1067,9 @@ class QPDFObjectHandle void objectWarning(std::string const& warning); void assertType(char const* type_name, bool istype); void dereference(); - void copyObject(std::set& visited, bool cross_indirect); + void copyObject(std::set& visited, bool cross_indirect, + bool first_level_only); + void shallowCopyInternal(QPDFObjectHandle& oh, bool first_level_only); void releaseResolved(); static void setObjectDescriptionFromInput( QPDFObjectHandle, QPDF*, std::string const&, -- cgit v1.2.3-54-g00ecf