From 0289b21c3b4d4d32b665e793dbf354ea34a23818 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sun, 20 Nov 2022 13:56:03 +0000 Subject: [PATCH] Remove redundant QPDFObjectHandle::copyObject2 copyObject2 repeats a second time what new_obj = QPDFObjectHandle(obj->copy(true)) in shallowCopyInternal2 already did. --- include/qpdf/QPDFObjectHandle.hh | 1 - libqpdf/QPDFObjectHandle.cc | 64 -------------------------------- 2 files changed, 65 deletions(-) diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh index 718952fe..de9f51e9 100644 --- a/include/qpdf/QPDFObjectHandle.hh +++ b/include/qpdf/QPDFObjectHandle.hh @@ -1634,7 +1634,6 @@ class QPDFObjectHandle bool first_level_only, bool stop_at_streams); void shallowCopyInternal1(QPDFObjectHandle& oh, bool first_level_only); - void copyObject2(std::set& visited); void shallowCopyInternal2(QPDFObjectHandle& oh); void copyObject( std::set& visited, diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 2a112166..242e0fb2 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -2312,70 +2312,6 @@ QPDFObjectHandle::shallowCopyInternal2(QPDFObjectHandle& new_obj) throw std::runtime_error("attempt to make a shallow copy of a stream"); } new_obj = QPDFObjectHandle(obj->copy(true)); - - std::set visited; - new_obj.copyObject2(visited); -} - -void -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"); - } - - auto cur_og = getObjGen(); - if (cur_og.getObj() != 0) { - if (visited.count(cur_og)) { - throw std::runtime_error( - "loop detected while converting object from " - "indirect to direct"); - } - visited.insert(cur_og); - } - - if (isReserved()) { - // same as obj->copy(true) - throw std::logic_error("QPDFObjectHandle: attempting to make a" - " reserved object handle direct"); - } - - std::shared_ptr new_obj; - - if (isBool() || isInteger() || isName() || isNull() || isReal() || - 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)); - } - 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); - } - new_obj = QPDF_Dictionary::create(items); - } else { - throw std::logic_error("QPDFObjectHandle::makeDirectInternal: " - "unknown object type"); - } - - this->obj = new_obj; - - if (cur_og.getObj()) { - visited.erase(cur_og); - } } void