Commit 53f6c0a55a3202d102eec92654b728de3eda2201

Authored by m-holger
1 parent 1957ad1e

Use QPDFObjGen::set in QPDFPageObjectHelper::forEachXObject

Showing 1 changed file with 15 additions and 18 deletions
libqpdf/QPDFPageObjectHelper.cc
@@ -352,30 +352,27 @@ QPDFPageObjectHelper::forEachXObject( @@ -352,30 +352,27 @@ QPDFPageObjectHelper::forEachXObject(
352 "QPDFPageObjectHelper::forEachXObject", 352 "QPDFPageObjectHelper::forEachXObject",
353 recursive ? (this->oh.isFormXObject() ? 0 : 1) 353 recursive ? (this->oh.isFormXObject() ? 0 : 1)
354 : (this->oh.isFormXObject() ? 2 : 3)); 354 : (this->oh.isFormXObject() ? 2 : 3));
355 - std::set<QPDFObjGen> seen; 355 + QPDFObjGen::set seen;
356 std::list<QPDFPageObjectHelper> queue; 356 std::list<QPDFPageObjectHelper> queue;
357 queue.push_back(*this); 357 queue.push_back(*this);
358 while (!queue.empty()) { 358 while (!queue.empty()) {
359 - QPDFPageObjectHelper ph = queue.front();  
360 - queue.pop_front();  
361 - QPDFObjGen og = ph.oh.getObjGen();  
362 - if (seen.count(og)) {  
363 - continue;  
364 - }  
365 - seen.insert(og);  
366 - QPDFObjectHandle resources = ph.getAttribute("/Resources", false);  
367 - if (resources.isDictionary() && resources.hasKey("/XObject")) {  
368 - QPDFObjectHandle xobj_dict = resources.getKey("/XObject");  
369 - for (auto const& key: xobj_dict.getKeys()) {  
370 - QPDFObjectHandle obj = xobj_dict.getKey(key);  
371 - if ((!selector) || selector(obj)) {  
372 - action(obj, xobj_dict, key);  
373 - }  
374 - if (recursive && obj.isFormXObject()) {  
375 - queue.push_back(QPDFPageObjectHelper(obj)); 359 + auto& ph = queue.front();
  360 + if (seen.add(ph)) {
  361 + auto xobj_dict =
  362 + ph.getAttribute("/Resources", false).getKeyIfDict("/XObject");
  363 + if (xobj_dict.isDictionary()) {
  364 + for (auto const& key: xobj_dict.getKeys()) {
  365 + QPDFObjectHandle obj = xobj_dict.getKey(key);
  366 + if ((!selector) || selector(obj)) {
  367 + action(obj, xobj_dict, key);
  368 + }
  369 + if (recursive && obj.isFormXObject()) {
  370 + queue.emplace_back(obj);
  371 + }
376 } 372 }
377 } 373 }
378 } 374 }
  375 + queue.pop_front();
379 } 376 }
380 } 377 }
381 378