From 15e8d3a763e066e1a8d2bd54cc1e2117a54f7d7c Mon Sep 17 00:00:00 2001 From: m-holger Date: Sun, 20 Nov 2022 13:46:33 +0000 Subject: Remove redundant parameter first_level_only from QPDFObjectHandle::shallowCopyInternal2 and copyObject2 --- include/qpdf/QPDFObjectHandle.hh | 4 ++-- libqpdf/QPDFObjectHandle.cc | 22 ++++++++-------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh index 4157015e..718952fe 100644 --- a/include/qpdf/QPDFObjectHandle.hh +++ b/include/qpdf/QPDFObjectHandle.hh @@ -1634,8 +1634,8 @@ class QPDFObjectHandle bool first_level_only, bool stop_at_streams); void shallowCopyInternal1(QPDFObjectHandle& oh, bool first_level_only); - void copyObject2(std::set& visited, bool first_level_only); - void shallowCopyInternal2(QPDFObjectHandle& oh, bool first_level_only); + void copyObject2(std::set& visited); + void shallowCopyInternal2(QPDFObjectHandle& oh); void copyObject( std::set& visited, bool cross_indirect, diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index a830fe4b..2a112166 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -2299,13 +2299,12 @@ QPDFObjectHandle QPDFObjectHandle::unsafeShallowCopy() { QPDFObjectHandle result; - shallowCopyInternal2(result, true); + shallowCopyInternal2(result); return result; } void -QPDFObjectHandle::shallowCopyInternal2( - QPDFObjectHandle& new_obj, bool first_level_only) +QPDFObjectHandle::shallowCopyInternal2(QPDFObjectHandle& new_obj) { assertInitialized(); @@ -2315,16 +2314,16 @@ QPDFObjectHandle::shallowCopyInternal2( new_obj = QPDFObjectHandle(obj->copy(true)); std::set visited; - new_obj.copyObject2(visited, first_level_only); + new_obj.copyObject2(visited); } void -QPDFObjectHandle::copyObject2( - std::set& visited, bool first_level_only) +QPDFObjectHandle::copyObject2(std::set& visited) { assertInitialized(); if (isStream()) { + // same as obj->copy(true) throw std::runtime_error( "attempt to make a stream into a direct object"); } @@ -2340,6 +2339,7 @@ QPDFObjectHandle::copyObject2( } if (isReserved()) { + // same as obj->copy(true) throw std::logic_error("QPDFObjectHandle: attempting to make a" " reserved object handle direct"); } @@ -2350,26 +2350,20 @@ QPDFObjectHandle::copyObject2( isString()) { new_obj = obj->copy(true); } else if (isArray()) { + // same as obj->copy(true) std::vector items; auto array = asArray(); int n = array->getNItems(); for (int i = 0; i < n; ++i) { items.push_back(array->getItem(i)); - if ((!first_level_only) && !items.back().isIndirect()) - { - items.back().copyObject2(visited, first_level_only); - } } new_obj = QPDF_Array::create(items); } else if (isDictionary()) { + // same as obj->copy(true) std::map items; auto dict = asDictionary(); for (auto const& key: getKeys()) { items[key] = dict->getKey(key); - if ((!first_level_only) && !items[key].isIndirect()) - { - items[key].copyObject2(visited, first_level_only); - } } new_obj = QPDF_Dictionary::create(items); } else { -- cgit v1.2.3-54-g00ecf