From 26de2d5c73bc0de4dd676282973403663a2a9b36 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sun, 17 Aug 2025 12:40:16 +0100 Subject: [PATCH] Refactor `NNTreeImpl::compareKeyItem` and `compareKeyKid`: replace `getArrayItem` and `getArrayNItems` with subscript operators for readability and cleaner syntax. --- libqpdf/NNTree.cc | 12 ++++-------- qpdf/qpdf.testcov | 2 -- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/libqpdf/NNTree.cc b/libqpdf/NNTree.cc index 0ac4576..2257154 100644 --- a/libqpdf/NNTree.cc +++ b/libqpdf/NNTree.cc @@ -766,23 +766,19 @@ NNTreeImpl::binarySearch( int NNTreeImpl::compareKeyItem(QPDFObjectHandle& key, QPDFObjectHandle& items, int idx) { - if (!((items.isArray() && (items.getArrayNItems() > (2 * idx)) && - details.keyValid(items.getArrayItem(2 * idx))))) { - QTC::TC("qpdf", "NNTree item is wrong type"); + if (!(std::cmp_greater(items.size(), 2 * idx) && details.keyValid(items[2 * idx]))) { error(oh, ("item at index " + std::to_string(2 * idx) + " is not the right type")); } - return details.compareKeys(key, items.getArrayItem(2 * idx)); + return details.compareKeys(key, items[2 * idx]); } int NNTreeImpl::compareKeyKid(QPDFObjectHandle& key, QPDFObjectHandle& kids, int idx) { - if (!(kids.isArray() && (idx < kids.getArrayNItems()) && - kids.getArrayItem(idx).isDictionary())) { - QTC::TC("qpdf", "NNTree kid is invalid"); + if (!(std::cmp_less(idx, kids.size()) && kids[idx].isDictionary())) { error(oh, "invalid kid at index " + std::to_string(idx)); } - return withinLimits(key, kids.getArrayItem(idx)); + return withinLimits(key, kids[idx]); } void diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov index f867d13..a12d39a 100644 --- a/qpdf/qpdf.testcov +++ b/qpdf/qpdf.testcov @@ -537,8 +537,6 @@ NNTree split second half item 0 NNTree split parent 0 NNTree split second half kid 0 NNTree missing limits 0 -NNTree item is wrong type 0 -NNTree kid is invalid 0 NNTree node is not a dictionary 0 NNTree limits didn't change 0 NNTree increment end() 0 -- libgit2 0.21.4