Commit bfc2cf849724adefc6b7af6ab774efc9cf70f622

Authored by m-holger
1 parent 1240c5ee

Refactor `QPDFJob`: replace `getArrayNItems` with `size`, use `emplace_back`, si…

…mplify array traversal, and centralize `empty` checks for improved clarity and efficiency.
libqpdf/QPDFJob.cc
... ... @@ -1082,7 +1082,7 @@ QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf)
1082 1082 dp_array = decode_parms;
1083 1083 } else {
1084 1084 dp_array = QPDFObjectHandle::newArray();
1085   - for (int i = 0; i < filters.getArrayNItems(); ++i) {
  1085 + for (size_t i = 0; i < filters.size(); ++i) {
1086 1086 dp_array.appendItem(decode_parms);
1087 1087 }
1088 1088 }
... ... @@ -2322,7 +2322,7 @@ QPDFJob::shouldRemoveUnreferencedResources(QPDF&amp; pdf)
2322 2322 });
2323 2323  
2324 2324 std::list<QPDFObjectHandle> queue;
2325   - queue.push_back(pdf.getRoot().getKey("/Pages"));
  2325 + queue.emplace_back(pdf.getRoot().getKey("/Pages"));
2326 2326 while (!queue.empty()) {
2327 2327 QPDFObjectHandle node = *queue.begin();
2328 2328 queue.pop_front();
... ... @@ -2341,9 +2341,8 @@ QPDFJob::shouldRemoveUnreferencedResources(QPDF&amp; pdf)
2341 2341 });
2342 2342 return true;
2343 2343 }
2344   - int n = kids.getArrayNItems();
2345   - for (int i = 0; i < n; ++i) {
2346   - queue.push_back(kids.getArrayItem(i));
  2344 + for (auto const& kid: kids.as_array()) {
  2345 + queue.emplace_back(kid);
2347 2346 }
2348 2347 } else {
2349 2348 // This is a leaf node or a form XObject.
... ... @@ -2670,12 +2669,10 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2670 2669 new_fields.appendItem(field);
2671 2670 }
2672 2671 }
2673   - if (new_fields.getArrayNItems() > 0) {
2674   - QTC::TC("qpdf", "QPDFJob keep some fields in pages");
2675   - acroform.replaceKey("/Fields", new_fields);
2676   - } else {
2677   - QTC::TC("qpdf", "QPDFJob no more fields in pages");
  2672 + if (new_fields.empty()) {
2678 2673 pdf.getRoot().removeKey("/AcroForm");
  2674 + } else {
  2675 + acroform.replaceKey("/Fields", new_fields);
2679 2676 }
2680 2677 }
2681 2678 }
... ...
qpdf/qpdf.testcov
... ... @@ -573,9 +573,7 @@ QPDFAcroFormDocumentHelper copy annotation 3
573 573 QPDFAcroFormDocumentHelper field with parent 3
574 574 QPDFAcroFormDocumentHelper modify ap matrix 0
575 575 QPDFJob copy form fields in split_pages 0
576   -QPDFJob keep some fields in pages 0
577 576 QPDFJob pages keeping field from original 0
578   -QPDFJob no more fields in pages 0
579 577 QPDFObjectHandle merge reuse 0
580 578 QPDFObjectHandle merge generate 0
581 579 QPDFFormFieldObjectHelper get font from /DR 0
... ...