From b6a5bdb102e40273e574f7e6afe208f22b072aee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Tue, 5 May 2026 16:33:22 +0200 Subject: [PATCH] Use segmented_find_if to take advantage of potential unrolling --- .../experimental/segmented_search.hpp | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/include/boost/container/experimental/segmented_search.hpp b/include/boost/container/experimental/segmented_search.hpp index 1baef6a..e9fc8b7 100644 --- a/include/boost/container/experimental/segmented_search.hpp +++ b/include/boost/container/experimental/segmented_search.hpp @@ -162,24 +162,29 @@ typename algo_enable_if_c< segmented_search_dispatch (FwdIt1 first, Sent1 last, FwdIt2 s_first, Sent2 s_last, Tag) { - // No top-level "s_first == s_last" guard is needed: the inner - // "if(s_it == s_last) return first;" below handles the empty-needle case - // (returning the current first, which equals the original first on the - // first outer iteration). When first == last the outer loop is skipped - // and we return last, which also equals first. - for(; first != last; ++first) { + if (s_first == s_last) + return first; + + equal_to_deref eq(s_first); + + while (first != last) { + first = boost::container::segmented_find_if(first, last, eq); + if (first == last) + return last; + FwdIt1 it = first; FwdIt2 s_it = s_first; for(;;) { + ++it; + ++s_it; if(s_it == s_last) return first; if(it == last) return last; if(!(*it == *s_it)) break; - ++it; - ++s_it; } + ++first; } return last; }