Commit 0289b21c3b4d4d32b665e793dbf354ea34a23818

Authored by m-holger
Committed by Jay Berkenbilt
1 parent 15e8d3a7

Remove redundant QPDFObjectHandle::copyObject2

copyObject2 repeats a second time what
new_obj = QPDFObjectHandle(obj->copy(true))
in shallowCopyInternal2 already did.
include/qpdf/QPDFObjectHandle.hh
@@ -1634,7 +1634,6 @@ class QPDFObjectHandle @@ -1634,7 +1634,6 @@ 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);  
1638 void shallowCopyInternal2(QPDFObjectHandle& oh); 1637 void shallowCopyInternal2(QPDFObjectHandle& oh);
1639 void copyObject( 1638 void copyObject(
1640 std::set<QPDFObjGen>& visited, 1639 std::set<QPDFObjGen>& visited,
libqpdf/QPDFObjectHandle.cc
@@ -2312,70 +2312,6 @@ QPDFObjectHandle::shallowCopyInternal2(QPDFObjectHandle&amp; new_obj) @@ -2312,70 +2312,6 @@ QPDFObjectHandle::shallowCopyInternal2(QPDFObjectHandle&amp; new_obj)
2312 throw std::runtime_error("attempt to make a shallow copy of a stream"); 2312 throw std::runtime_error("attempt to make a shallow copy of a stream");
2313 } 2313 }
2314 new_obj = QPDFObjectHandle(obj->copy(true)); 2314 new_obj = QPDFObjectHandle(obj->copy(true));
2315 -  
2316 - std::set<QPDFObjGen> visited;  
2317 - new_obj.copyObject2(visited);  
2318 -}  
2319 -  
2320 -void  
2321 -QPDFObjectHandle::copyObject2(std::set<QPDFObjGen>& visited)  
2322 -{  
2323 - assertInitialized();  
2324 -  
2325 - if (isStream()) {  
2326 - // same as obj->copy(true)  
2327 - throw std::runtime_error(  
2328 - "attempt to make a stream into a direct object");  
2329 - }  
2330 -  
2331 - auto cur_og = getObjGen();  
2332 - if (cur_og.getObj() != 0) {  
2333 - if (visited.count(cur_og)) {  
2334 - throw std::runtime_error(  
2335 - "loop detected while converting object from "  
2336 - "indirect to direct");  
2337 - }  
2338 - visited.insert(cur_og);  
2339 - }  
2340 -  
2341 - if (isReserved()) {  
2342 - // same as obj->copy(true)  
2343 - throw std::logic_error("QPDFObjectHandle: attempting to make a"  
2344 - " reserved object handle direct");  
2345 - }  
2346 -  
2347 - std::shared_ptr<QPDFObject> new_obj;  
2348 -  
2349 - if (isBool() || isInteger() || isName() || isNull() || isReal() ||  
2350 - isString()) {  
2351 - new_obj = obj->copy(true);  
2352 - } else if (isArray()) {  
2353 - // same as obj->copy(true)  
2354 - std::vector<QPDFObjectHandle> items;  
2355 - auto array = asArray();  
2356 - int n = array->getNItems();  
2357 - for (int i = 0; i < n; ++i) {  
2358 - items.push_back(array->getItem(i));  
2359 - }  
2360 - new_obj = QPDF_Array::create(items);  
2361 - } else if (isDictionary()) {  
2362 - // same as obj->copy(true)  
2363 - std::map<std::string, QPDFObjectHandle> items;  
2364 - auto dict = asDictionary();  
2365 - for (auto const& key: getKeys()) {  
2366 - items[key] = dict->getKey(key);  
2367 - }  
2368 - new_obj = QPDF_Dictionary::create(items);  
2369 - } else {  
2370 - throw std::logic_error("QPDFObjectHandle::makeDirectInternal: "  
2371 - "unknown object type");  
2372 - }  
2373 -  
2374 - this->obj = new_obj;  
2375 -  
2376 - if (cur_og.getObj()) {  
2377 - visited.erase(cur_og);  
2378 - }  
2379 } 2315 }
2380 2316
2381 void 2317 void