2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-21 19:32:20 +00:00

Remove redundant parameter first_level_only from QPDFObjectHandle::shallowCopyInternal2 and copyObject2

This commit is contained in:
m-holger 2022-11-20 13:46:33 +00:00 committed by Jay Berkenbilt
parent 0827b1096e
commit 15e8d3a763
2 changed files with 10 additions and 16 deletions

View File

@ -1634,8 +1634,8 @@ class QPDFObjectHandle
bool first_level_only, bool first_level_only,
bool stop_at_streams); bool stop_at_streams);
void shallowCopyInternal1(QPDFObjectHandle& oh, bool first_level_only); void shallowCopyInternal1(QPDFObjectHandle& oh, bool first_level_only);
void copyObject2(std::set<QPDFObjGen>& visited, bool first_level_only); void copyObject2(std::set<QPDFObjGen>& visited);
void shallowCopyInternal2(QPDFObjectHandle& oh, bool first_level_only); void shallowCopyInternal2(QPDFObjectHandle& oh);
void copyObject( void copyObject(
std::set<QPDFObjGen>& visited, std::set<QPDFObjGen>& visited,
bool cross_indirect, bool cross_indirect,

View File

@ -2299,13 +2299,12 @@ QPDFObjectHandle
QPDFObjectHandle::unsafeShallowCopy() QPDFObjectHandle::unsafeShallowCopy()
{ {
QPDFObjectHandle result; QPDFObjectHandle result;
shallowCopyInternal2(result, true); shallowCopyInternal2(result);
return result; return result;
} }
void void
QPDFObjectHandle::shallowCopyInternal2( QPDFObjectHandle::shallowCopyInternal2(QPDFObjectHandle& new_obj)
QPDFObjectHandle& new_obj, bool first_level_only)
{ {
assertInitialized(); assertInitialized();
@ -2315,16 +2314,16 @@ QPDFObjectHandle::shallowCopyInternal2(
new_obj = QPDFObjectHandle(obj->copy(true)); new_obj = QPDFObjectHandle(obj->copy(true));
std::set<QPDFObjGen> visited; std::set<QPDFObjGen> visited;
new_obj.copyObject2(visited, first_level_only); new_obj.copyObject2(visited);
} }
void void
QPDFObjectHandle::copyObject2( QPDFObjectHandle::copyObject2(std::set<QPDFObjGen>& visited)
std::set<QPDFObjGen>& visited, bool first_level_only)
{ {
assertInitialized(); assertInitialized();
if (isStream()) { if (isStream()) {
// same as obj->copy(true)
throw std::runtime_error( throw std::runtime_error(
"attempt to make a stream into a direct object"); "attempt to make a stream into a direct object");
} }
@ -2340,6 +2339,7 @@ QPDFObjectHandle::copyObject2(
} }
if (isReserved()) { if (isReserved()) {
// same as obj->copy(true)
throw std::logic_error("QPDFObjectHandle: attempting to make a" throw std::logic_error("QPDFObjectHandle: attempting to make a"
" reserved object handle direct"); " reserved object handle direct");
} }
@ -2350,26 +2350,20 @@ QPDFObjectHandle::copyObject2(
isString()) { isString()) {
new_obj = obj->copy(true); new_obj = obj->copy(true);
} else if (isArray()) { } else if (isArray()) {
// same as obj->copy(true)
std::vector<QPDFObjectHandle> items; std::vector<QPDFObjectHandle> items;
auto array = asArray(); auto array = asArray();
int n = array->getNItems(); int n = array->getNItems();
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
items.push_back(array->getItem(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); new_obj = QPDF_Array::create(items);
} else if (isDictionary()) { } else if (isDictionary()) {
// same as obj->copy(true)
std::map<std::string, QPDFObjectHandle> items; std::map<std::string, QPDFObjectHandle> items;
auto dict = asDictionary(); auto dict = asDictionary();
for (auto const& key: getKeys()) { for (auto const& key: getKeys()) {
items[key] = dict->getKey(key); 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); new_obj = QPDF_Dictionary::create(items);
} else { } else {