[libcxx-commits] [libcxx] [libc++] Optimize search_n (PR #171389)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 9 02:47:54 PST 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions h -- libcxx/include/__algorithm/ranges_search_n.h libcxx/include/__algorithm/search_n.h --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libcxx/include/__algorithm/search_n.h b/libcxx/include/__algorithm/search_n.h
index c48ced45c..bea0d9875 100644
--- a/libcxx/include/__algorithm/search_n.h
+++ b/libcxx/include/__algorithm/search_n.h
@@ -81,8 +81,8 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 std::pair<_Iter, _Iter> __se
     return std::make_pair(__last, __last);
 
   _Iter __try_match_until = __last - __count;
-  _Iter __match_start = __first;
-  _Iter __matched_until = __first;
+  _Iter __match_start     = __first;
+  _Iter __matched_until   = __first;
   while (true) {
     if (__match_start > __try_match_until)
       return std::make_pair(__last, __last);
@@ -95,7 +95,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 std::pair<_Iter, _Iter> __se
 
       if (!std::__invoke(__pred, std::__invoke(__proj, *--__check), __value)) {
         __matched_until = __match_start + __count;
-        __match_start = ++__check;
+        __match_start   = ++__check;
         break;
       }
     }

``````````

</details>


https://github.com/llvm/llvm-project/pull/171389


More information about the libcxx-commits mailing list