Commit 15e8d3a763e066e1a8d2bd54cc1e2117a54f7d7c
Committed by
Jay Berkenbilt
1 parent
0827b109
Remove redundant parameter first_level_only from QPDFObjectHandle::shallowCopyIn…
…ternal2 and copyObject2
Showing
2 changed files
with
10 additions
and
16 deletions
include/qpdf/QPDFObjectHandle.hh
| @@ -1634,8 +1634,8 @@ class QPDFObjectHandle | @@ -1634,8 +1634,8 @@ class QPDFObjectHandle | ||
| 1634 | bool first_level_only, | 1634 | bool first_level_only, |
| 1635 | bool stop_at_streams); | 1635 | bool stop_at_streams); |
| 1636 | void shallowCopyInternal1(QPDFObjectHandle& oh, bool first_level_only); | 1636 | void shallowCopyInternal1(QPDFObjectHandle& oh, bool first_level_only); |
| 1637 | - void copyObject2(std::set<QPDFObjGen>& visited, bool first_level_only); | ||
| 1638 | - void shallowCopyInternal2(QPDFObjectHandle& oh, bool first_level_only); | 1637 | + void copyObject2(std::set<QPDFObjGen>& visited); |
| 1638 | + void shallowCopyInternal2(QPDFObjectHandle& oh); | ||
| 1639 | void copyObject( | 1639 | void copyObject( |
| 1640 | std::set<QPDFObjGen>& visited, | 1640 | std::set<QPDFObjGen>& visited, |
| 1641 | bool cross_indirect, | 1641 | bool cross_indirect, |
libqpdf/QPDFObjectHandle.cc
| @@ -2299,13 +2299,12 @@ QPDFObjectHandle | @@ -2299,13 +2299,12 @@ QPDFObjectHandle | ||
| 2299 | QPDFObjectHandle::unsafeShallowCopy() | 2299 | QPDFObjectHandle::unsafeShallowCopy() |
| 2300 | { | 2300 | { |
| 2301 | QPDFObjectHandle result; | 2301 | QPDFObjectHandle result; |
| 2302 | - shallowCopyInternal2(result, true); | 2302 | + shallowCopyInternal2(result); |
| 2303 | return result; | 2303 | return result; |
| 2304 | } | 2304 | } |
| 2305 | 2305 | ||
| 2306 | void | 2306 | void |
| 2307 | -QPDFObjectHandle::shallowCopyInternal2( | ||
| 2308 | - QPDFObjectHandle& new_obj, bool first_level_only) | 2307 | +QPDFObjectHandle::shallowCopyInternal2(QPDFObjectHandle& new_obj) |
| 2309 | { | 2308 | { |
| 2310 | assertInitialized(); | 2309 | assertInitialized(); |
| 2311 | 2310 | ||
| @@ -2315,16 +2314,16 @@ QPDFObjectHandle::shallowCopyInternal2( | @@ -2315,16 +2314,16 @@ QPDFObjectHandle::shallowCopyInternal2( | ||
| 2315 | new_obj = QPDFObjectHandle(obj->copy(true)); | 2314 | new_obj = QPDFObjectHandle(obj->copy(true)); |
| 2316 | 2315 | ||
| 2317 | std::set<QPDFObjGen> visited; | 2316 | std::set<QPDFObjGen> visited; |
| 2318 | - new_obj.copyObject2(visited, first_level_only); | 2317 | + new_obj.copyObject2(visited); |
| 2319 | } | 2318 | } |
| 2320 | 2319 | ||
| 2321 | void | 2320 | void |
| 2322 | -QPDFObjectHandle::copyObject2( | ||
| 2323 | - std::set<QPDFObjGen>& visited, bool first_level_only) | 2321 | +QPDFObjectHandle::copyObject2(std::set<QPDFObjGen>& visited) |
| 2324 | { | 2322 | { |
| 2325 | assertInitialized(); | 2323 | assertInitialized(); |
| 2326 | 2324 | ||
| 2327 | if (isStream()) { | 2325 | if (isStream()) { |
| 2326 | + // same as obj->copy(true) | ||
| 2328 | throw std::runtime_error( | 2327 | throw std::runtime_error( |
| 2329 | "attempt to make a stream into a direct object"); | 2328 | "attempt to make a stream into a direct object"); |
| 2330 | } | 2329 | } |
| @@ -2340,6 +2339,7 @@ QPDFObjectHandle::copyObject2( | @@ -2340,6 +2339,7 @@ QPDFObjectHandle::copyObject2( | ||
| 2340 | } | 2339 | } |
| 2341 | 2340 | ||
| 2342 | if (isReserved()) { | 2341 | if (isReserved()) { |
| 2342 | + // same as obj->copy(true) | ||
| 2343 | throw std::logic_error("QPDFObjectHandle: attempting to make a" | 2343 | throw std::logic_error("QPDFObjectHandle: attempting to make a" |
| 2344 | " reserved object handle direct"); | 2344 | " reserved object handle direct"); |
| 2345 | } | 2345 | } |
| @@ -2350,26 +2350,20 @@ QPDFObjectHandle::copyObject2( | @@ -2350,26 +2350,20 @@ QPDFObjectHandle::copyObject2( | ||
| 2350 | isString()) { | 2350 | isString()) { |
| 2351 | new_obj = obj->copy(true); | 2351 | new_obj = obj->copy(true); |
| 2352 | } else if (isArray()) { | 2352 | } else if (isArray()) { |
| 2353 | + // same as obj->copy(true) | ||
| 2353 | std::vector<QPDFObjectHandle> items; | 2354 | std::vector<QPDFObjectHandle> items; |
| 2354 | auto array = asArray(); | 2355 | auto array = asArray(); |
| 2355 | int n = array->getNItems(); | 2356 | int n = array->getNItems(); |
| 2356 | for (int i = 0; i < n; ++i) { | 2357 | for (int i = 0; i < n; ++i) { |
| 2357 | items.push_back(array->getItem(i)); | 2358 | items.push_back(array->getItem(i)); |
| 2358 | - if ((!first_level_only) && !items.back().isIndirect()) | ||
| 2359 | - { | ||
| 2360 | - items.back().copyObject2(visited, first_level_only); | ||
| 2361 | - } | ||
| 2362 | } | 2359 | } |
| 2363 | new_obj = QPDF_Array::create(items); | 2360 | new_obj = QPDF_Array::create(items); |
| 2364 | } else if (isDictionary()) { | 2361 | } else if (isDictionary()) { |
| 2362 | + // same as obj->copy(true) | ||
| 2365 | std::map<std::string, QPDFObjectHandle> items; | 2363 | std::map<std::string, QPDFObjectHandle> items; |
| 2366 | auto dict = asDictionary(); | 2364 | auto dict = asDictionary(); |
| 2367 | for (auto const& key: getKeys()) { | 2365 | for (auto const& key: getKeys()) { |
| 2368 | items[key] = dict->getKey(key); | 2366 | items[key] = dict->getKey(key); |
| 2369 | - if ((!first_level_only) && !items[key].isIndirect()) | ||
| 2370 | - { | ||
| 2371 | - items[key].copyObject2(visited, first_level_only); | ||
| 2372 | - } | ||
| 2373 | } | 2367 | } |
| 2374 | new_obj = QPDF_Dictionary::create(items); | 2368 | new_obj = QPDF_Dictionary::create(items); |
| 2375 | } else { | 2369 | } else { |