Skip to content

Commit

Permalink
Another minor source code size decrease
Browse files Browse the repository at this point in the history
  • Loading branch information
andreilitvin committed Dec 10, 2024
1 parent 97a8400 commit 57fc226
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/lib/support/SpanSearchValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,15 @@ class SpanSearchValue
FindIndexUsingHint(const N & needle, Span<H> haystack, unsigned & hint,
bool (*haystackValueMatchesNeedle)(const N &, const typename std::remove_const<H>::type &))
{
if (hint < haystack.size())
{
if (haystackValueMatchesNeedle(needle, haystack[hint]))
{
return hint;
}
}
// search starts at `hint` rather than 0
const unsigned hayscackSize = static_cast<unsigned>(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;
}
}

Expand Down

0 comments on commit 57fc226

Please sign in to comment.