From 57fc2261ccf69c268454ade44a75aee0e9f15bda Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 10 Dec 2024 14:51:51 -0500 Subject: [PATCH] Another minor source code size decrease --- src/lib/support/SpanSearchValue.h | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/lib/support/SpanSearchValue.h b/src/lib/support/SpanSearchValue.h index df65295681ec9c..60087756e6c2d4 100644 --- a/src/lib/support/SpanSearchValue.h +++ b/src/lib/support/SpanSearchValue.h @@ -122,20 +122,15 @@ class SpanSearchValue FindIndexUsingHint(const N & needle, Span haystack, unsigned & hint, bool (*haystackValueMatchesNeedle)(const N &, const typename std::remove_const::type &)) { - if (hint < haystack.size()) - { - if (haystackValueMatchesNeedle(needle, haystack[hint])) - { - return hint; - } - } + // search starts at `hint` rather than 0 + const unsigned hayscackSize = static_cast(haystack.size()); - for (unsigned i = 0; i < haystack.size(); i++) + for (unsigned i = 0, checkIndex = hint; i < hayscackSize; i++, checkIndex++) { - if (haystackValueMatchesNeedle(needle, haystack[i])) + if (haystackValueMatchesNeedle(needle, haystack[checkIndex % hayscackSize])) { - hint = i; - return i; + hint = checkIndex % hayscackSize; + return checkIndex % hayscackSize; } }