Commit 1240c5eecf63443bc31812c11e47738c9a06a990
1 parent
f699aacb
Refactor `QPDFAcroFormDocumentHelper`: replace `getArrayNItems` with `size`, int…
…roduce `empty` checks, and use `std::cmp_less` and `emplace_back` for better clarity and efficiency.
Showing
1 changed file
with
8 additions
and
5 deletions
libqpdf/QPDFAcroFormDocumentHelper.cc
| ... | ... | @@ -7,6 +7,8 @@ |
| 7 | 7 | #include <qpdf/QUtil.hh> |
| 8 | 8 | #include <qpdf/ResourceFinder.hh> |
| 9 | 9 | |
| 10 | +#include <utility> | |
| 11 | + | |
| 10 | 12 | using namespace qpdf; |
| 11 | 13 | using namespace std::literals; |
| 12 | 14 | |
| ... | ... | @@ -139,7 +141,7 @@ QPDFAcroFormDocumentHelper::removeFormFields(std::set<QPDFObjGen> const& to_remo |
| 139 | 141 | } |
| 140 | 142 | |
| 141 | 143 | int i = 0; |
| 142 | - while (i < fields.getArrayNItems()) { | |
| 144 | + while (std::cmp_less(i, fields.size())) { | |
| 143 | 145 | auto field = fields.getArrayItem(i); |
| 144 | 146 | if (to_remove.contains(field.getObjGen())) { |
| 145 | 147 | fields.eraseItem(i); |
| ... | ... | @@ -896,12 +898,13 @@ QPDFAcroFormDocumentHelper::transformAnnotations( |
| 896 | 898 | } |
| 897 | 899 | } |
| 898 | 900 | auto kids = obj.getKey("/Kids"); |
| 899 | - if (kids.isArray()) { | |
| 900 | - for (int i = 0; i < kids.getArrayNItems(); ++i) { | |
| 901 | + int sz = static_cast<int>(kids.size()); | |
| 902 | + if (sz != 1 || kids.isArray()) { | |
| 903 | + for (int i = 0; i < sz; ++i) { | |
| 901 | 904 | auto kid = kids.getArrayItem(i); |
| 902 | 905 | if (maybe_copy_object(kid)) { |
| 903 | 906 | kids.setArrayItem(i, kid); |
| 904 | - queue.push_back(kid); | |
| 907 | + queue.emplace_back(kid); | |
| 905 | 908 | } |
| 906 | 909 | } |
| 907 | 910 | } |
| ... | ... | @@ -1013,7 +1016,7 @@ QPDFAcroFormDocumentHelper::fixCopiedAnnotations( |
| 1013 | 1016 | std::set<QPDFObjGen>* added_fields) |
| 1014 | 1017 | { |
| 1015 | 1018 | auto old_annots = from_page.getKey("/Annots"); |
| 1016 | - if ((!old_annots.isArray()) || (old_annots.getArrayNItems() == 0)) { | |
| 1019 | + if (old_annots.empty() || !old_annots.isArray()) { | |
| 1017 | 1020 | return; |
| 1018 | 1021 | } |
| 1019 | 1022 | ... | ... |