Commit 0c45bd87491faa2619de9d22212a00c548d421c3
1 parent
ae2d6239
Use QPDFObjGen::set in QPDFJob::shouldRemoveUnreferencedResources
Showing
1 changed file
with
8 additions
and
13 deletions
libqpdf/QPDFJob.cc
| ... | ... | @@ -2451,8 +2451,8 @@ QPDFJob::shouldRemoveUnreferencedResources(QPDF& pdf) |
| 2451 | 2451 | |
| 2452 | 2452 | // Return true as soon as we find any shared resources. |
| 2453 | 2453 | |
| 2454 | - std::set<QPDFObjGen> resources_seen; // shared resources detection | |
| 2455 | - std::set<QPDFObjGen> nodes_seen; // loop detection | |
| 2454 | + QPDFObjGen::set resources_seen; // shared resources detection | |
| 2455 | + QPDFObjGen::set nodes_seen; // loop detection | |
| 2456 | 2456 | |
| 2457 | 2457 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { |
| 2458 | 2458 | v << prefix << ": " << pdf.getFilename() |
| ... | ... | @@ -2465,10 +2465,9 @@ QPDFJob::shouldRemoveUnreferencedResources(QPDF& pdf) |
| 2465 | 2465 | QPDFObjectHandle node = *queue.begin(); |
| 2466 | 2466 | queue.pop_front(); |
| 2467 | 2467 | QPDFObjGen og = node.getObjGen(); |
| 2468 | - if (nodes_seen.count(og)) { | |
| 2468 | + if (!nodes_seen.add(og)) { | |
| 2469 | 2469 | continue; |
| 2470 | 2470 | } |
| 2471 | - nodes_seen.insert(og); | |
| 2472 | 2471 | QPDFObjectHandle dict = node.isStream() ? node.getDict() : node; |
| 2473 | 2472 | QPDFObjectHandle kids = dict.getKey("/Kids"); |
| 2474 | 2473 | if (kids.isArray()) { |
| ... | ... | @@ -2489,33 +2488,29 @@ QPDFJob::shouldRemoveUnreferencedResources(QPDF& pdf) |
| 2489 | 2488 | // This is a leaf node or a form XObject. |
| 2490 | 2489 | QPDFObjectHandle resources = dict.getKey("/Resources"); |
| 2491 | 2490 | if (resources.isIndirect()) { |
| 2492 | - QPDFObjGen resources_og = resources.getObjGen(); | |
| 2493 | - if (resources_seen.count(resources_og)) { | |
| 2491 | + if (!resources_seen.add(resources)) { | |
| 2494 | 2492 | QTC::TC("qpdf", "QPDFJob found shared resources in leaf"); |
| 2495 | 2493 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { |
| 2496 | 2494 | v << " found shared resources in leaf node " |
| 2497 | 2495 | << og.unparse(' ') << ": " |
| 2498 | - << resources_og.unparse(' ') << "\n"; | |
| 2496 | + << resources.getObjGen().unparse(' ') << "\n"; | |
| 2499 | 2497 | }); |
| 2500 | 2498 | return true; |
| 2501 | 2499 | } |
| 2502 | - resources_seen.insert(resources_og); | |
| 2503 | 2500 | } |
| 2504 | 2501 | QPDFObjectHandle xobject = |
| 2505 | 2502 | (resources.isDictionary() ? resources.getKey("/XObject") |
| 2506 | 2503 | : QPDFObjectHandle::newNull()); |
| 2507 | 2504 | if (xobject.isIndirect()) { |
| 2508 | - QPDFObjGen xobject_og = xobject.getObjGen(); | |
| 2509 | - if (resources_seen.count(xobject_og)) { | |
| 2505 | + if (!resources_seen.add(xobject)) { | |
| 2510 | 2506 | QTC::TC("qpdf", "QPDFJob found shared xobject in leaf"); |
| 2511 | 2507 | doIfVerbose([&](Pipeline& v, std::string const& prefix) { |
| 2512 | 2508 | v << " found shared xobject in leaf node " |
| 2513 | - << og.unparse(' ') << ": " << xobject_og.unparse(' ') | |
| 2514 | - << "\n"; | |
| 2509 | + << og.unparse(' ') << ": " | |
| 2510 | + << xobject.getObjGen().unparse(' ') << "\n"; | |
| 2515 | 2511 | }); |
| 2516 | 2512 | return true; |
| 2517 | 2513 | } |
| 2518 | - resources_seen.insert(xobject_og); | |
| 2519 | 2514 | } |
| 2520 | 2515 | if (xobject.isDictionary()) { |
| 2521 | 2516 | for (auto const& k: xobject.getKeys()) { | ... | ... |