Commit 4257c7bd4ea075530ee546050a2335e9ffae3e5e

Authored by m-holger
1 parent bfc2cf84

Refactor `QPDFFormFieldObjectHelper`, `QPDFPageObjectHelper`, and `QPDFOutlineOb…

…jectHelper`: replace `getArrayNItems` with `size`, simplify array traversal, and centralize `empty` checks for improved clarity and efficiency.
libqpdf/QPDFFormFieldObjectHelper.cc
@@ -281,7 +281,7 @@ QPDFFormFieldObjectHelper::getChoices() @@ -281,7 +281,7 @@ QPDFFormFieldObjectHelper::getChoices()
281 for (auto const& item: getInheritableFieldValue("/Opt").as_array()) { 281 for (auto const& item: getInheritableFieldValue("/Opt").as_array()) {
282 if (item.isString()) { 282 if (item.isString()) {
283 result.emplace_back(item.getUTF8Value()); 283 result.emplace_back(item.getUTF8Value());
284 - } else if (item.isArray() && item.getArrayNItems() == 2) { 284 + } else if (item.size() == 2) {
285 auto display = item.getArrayItem(1); 285 auto display = item.getArrayItem(1);
286 if (display.isString()) { 286 if (display.isString()) {
287 result.emplace_back(display.getUTF8Value()); 287 result.emplace_back(display.getUTF8Value());
libqpdf/QPDFOutlineObjectHelper.cc
@@ -75,7 +75,7 @@ QPDFObjectHandle @@ -75,7 +75,7 @@ QPDFObjectHandle
75 QPDFOutlineObjectHelper::getDestPage() 75 QPDFOutlineObjectHelper::getDestPage()
76 { 76 {
77 QPDFObjectHandle dest = getDest(); 77 QPDFObjectHandle dest = getDest();
78 - if ((dest.isArray()) && (dest.getArrayNItems() > 0)) { 78 + if (!dest.empty() && dest.isArray()) {
79 return dest.getArrayItem(0); 79 return dest.getArrayItem(0);
80 } 80 }
81 return QPDFObjectHandle::newNull(); 81 return QPDFObjectHandle::newNull();
libqpdf/QPDFPageObjectHelper.cc
@@ -445,14 +445,9 @@ std::vector<QPDFAnnotationObjectHelper> @@ -445,14 +445,9 @@ std::vector<QPDFAnnotationObjectHelper>
445 QPDFPageObjectHelper::getAnnotations(std::string const& only_subtype) 445 QPDFPageObjectHelper::getAnnotations(std::string const& only_subtype)
446 { 446 {
447 std::vector<QPDFAnnotationObjectHelper> result; 447 std::vector<QPDFAnnotationObjectHelper> result;
448 - QPDFObjectHandle annots = oh().getKey("/Annots");  
449 - if (annots.isArray()) {  
450 - int nannots = annots.getArrayNItems();  
451 - for (int i = 0; i < nannots; ++i) {  
452 - QPDFObjectHandle annot = annots.getArrayItem(i);  
453 - if (annot.isDictionaryOfType("", only_subtype)) {  
454 - result.emplace_back(annot);  
455 - } 448 + for (auto const& annot: oh().getKey("/Annots").as_array()) {
  449 + if (annot.isDictionaryOfType("", only_subtype)) {
  450 + result.emplace_back(annot);
456 } 451 }
457 } 452 }
458 return result; 453 return result;