From b8bc3ca3aec57e3ebeabf0f617d6cef0e49f656a Mon Sep 17 00:00:00 2001 From: m-holger Date: Thu, 28 Aug 2025 12:56:25 +0100 Subject: [PATCH] Remove `withinLimits` method and inline its logic into `compareKeyKid` in `NNTreeImpl` --- libqpdf/NNTree.cc | 34 ++++++++++++++-------------------- libqpdf/qpdf/NNTree.hh | 4 +--- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/libqpdf/NNTree.cc b/libqpdf/NNTree.cc index 5662693..c82fc3a 100644 --- a/libqpdf/NNTree.cc +++ b/libqpdf/NNTree.cc @@ -667,9 +667,9 @@ NNTreeImpl::last() int NNTreeImpl::compareKeys(QPDFObjectHandle a, QPDFObjectHandle b) const { - // We don't call this without calling keyValid first - qpdf_assert_debug(keyValid(a)); - qpdf_assert_debug(keyValid(b)); + // We don't call this without calling keyValid first + qpdf_assert_debug(keyValid(a)); + qpdf_assert_debug(keyValid(b)); if (key_type == ::ot_string) { auto as = a.getUTF8Value(); auto bs = b.getUTF8Value(); @@ -681,22 +681,6 @@ NNTreeImpl::compareKeys(QPDFObjectHandle a, QPDFObjectHandle b) const } int -NNTreeImpl::withinLimits(QPDFObjectHandle const& key, QPDFObjectHandle const& node) -{ - Array limits = node.getKey("/Limits"); - if (!(keyValid(limits[0]) && keyValid(limits[1]))) { - error(node, "node is missing /Limits"); - } - if (compareKeys(key, limits[0]) < 0) { - return -1; - } - if (compareKeys(key, limits[1]) > 0) { - return 1; - } - return 0; -} - -int NNTreeImpl::binarySearch( QPDFObjectHandle key, QPDFObjectHandle items, @@ -755,7 +739,17 @@ NNTreeImpl::compareKeyKid(QPDFObjectHandle& key, QPDFObjectHandle& kids, int idx if (!(std::cmp_less(idx, kids.size()) && kids[idx].isDictionary())) { error(oh, "invalid kid at index " + std::to_string(idx)); } - return withinLimits(key, kids[idx]); + Array limits = kids[idx].getKey("/Limits"); + if (!(keyValid(limits[0]) && keyValid(limits[1]))) { + error(kids[idx], "node is missing /Limits"); + } + if (compareKeys(key, limits[0]) < 0) { + return -1; + } + if (compareKeys(key, limits[1]) > 0) { + return 1; + } + return 0; } void diff --git a/libqpdf/qpdf/NNTree.hh b/libqpdf/qpdf/NNTree.hh index a0ca038..4e77ff1 100644 --- a/libqpdf/qpdf/NNTree.hh +++ b/libqpdf/qpdf/NNTree.hh @@ -110,7 +110,6 @@ class NNTreeImpl private: void repair(); iterator findInternal(QPDFObjectHandle const& key, bool return_prev_if_not_found = false); - int withinLimits(QPDFObjectHandle const& key, QPDFObjectHandle const& node); int binarySearch( QPDFObjectHandle key, QPDFObjectHandle items, @@ -132,8 +131,7 @@ class NNTreeImpl { return o.resolved_type_code() == key_type; } - int - compareKeys(QPDFObjectHandle a, QPDFObjectHandle b) const; + int compareKeys(QPDFObjectHandle a, QPDFObjectHandle b) const; QPDF& qpdf; int split_threshold{32}; -- libgit2 0.21.4