Commit 26de2d5c73bc0de4dd676282973403663a2a9b36

Authored by m-holger
1 parent 61a676cc

Refactor `NNTreeImpl::compareKeyItem` and `compareKeyKid`: replace `getArrayItem…

…` and `getArrayNItems` with subscript operators for readability and cleaner syntax.
libqpdf/NNTree.cc
@@ -766,23 +766,19 @@ NNTreeImpl::binarySearch( @@ -766,23 +766,19 @@ NNTreeImpl::binarySearch(
766 int 766 int
767 NNTreeImpl::compareKeyItem(QPDFObjectHandle& key, QPDFObjectHandle& items, int idx) 767 NNTreeImpl::compareKeyItem(QPDFObjectHandle& key, QPDFObjectHandle& items, int idx)
768 { 768 {
769 - if (!((items.isArray() && (items.getArrayNItems() > (2 * idx)) &&  
770 - details.keyValid(items.getArrayItem(2 * idx))))) {  
771 - QTC::TC("qpdf", "NNTree item is wrong type"); 769 + if (!(std::cmp_greater(items.size(), 2 * idx) && details.keyValid(items[2 * idx]))) {
772 error(oh, ("item at index " + std::to_string(2 * idx) + " is not the right type")); 770 error(oh, ("item at index " + std::to_string(2 * idx) + " is not the right type"));
773 } 771 }
774 - return details.compareKeys(key, items.getArrayItem(2 * idx)); 772 + return details.compareKeys(key, items[2 * idx]);
775 } 773 }
776 774
777 int 775 int
778 NNTreeImpl::compareKeyKid(QPDFObjectHandle& key, QPDFObjectHandle& kids, int idx) 776 NNTreeImpl::compareKeyKid(QPDFObjectHandle& key, QPDFObjectHandle& kids, int idx)
779 { 777 {
780 - if (!(kids.isArray() && (idx < kids.getArrayNItems()) &&  
781 - kids.getArrayItem(idx).isDictionary())) {  
782 - QTC::TC("qpdf", "NNTree kid is invalid"); 778 + if (!(std::cmp_less(idx, kids.size()) && kids[idx].isDictionary())) {
783 error(oh, "invalid kid at index " + std::to_string(idx)); 779 error(oh, "invalid kid at index " + std::to_string(idx));
784 } 780 }
785 - return withinLimits(key, kids.getArrayItem(idx)); 781 + return withinLimits(key, kids[idx]);
786 } 782 }
787 783
788 void 784 void
qpdf/qpdf.testcov
@@ -537,8 +537,6 @@ NNTree split second half item 0 @@ -537,8 +537,6 @@ NNTree split second half item 0
537 NNTree split parent 0 537 NNTree split parent 0
538 NNTree split second half kid 0 538 NNTree split second half kid 0
539 NNTree missing limits 0 539 NNTree missing limits 0
540 -NNTree item is wrong type 0  
541 -NNTree kid is invalid 0  
542 NNTree node is not a dictionary 0 540 NNTree node is not a dictionary 0
543 NNTree limits didn't change 0 541 NNTree limits didn't change 0
544 NNTree increment end() 0 542 NNTree increment end() 0