[libcxx-commits] [libcxx] [libc++] Optimize ranges::for_each for iterating over __trees (PR #164405)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 21 05:09:53 PDT 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 ,cpp,h -- libcxx/include/__algorithm/specialized_algorithms.h libcxx/include/__algorithm/ranges_for_each.h libcxx/include/__tree libcxx/include/map libcxx/include/set libcxx/test/benchmarks/algorithms/nonmodifying/for_each.bench.cpp --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/__tree b/libcxx/include/__tree
index b027cef99..21601a111 100644
--- a/libcxx/include/__tree
+++ b/libcxx/include/__tree
@@ -1480,9 +1480,9 @@ struct __specialized_algorithm<_Algorithm::__for_each, __tree<_Tp, _Compare, _Al
   using __node_pointer _LIBCPP_NODEBUG = typename __tree::__node_pointer;
 
   template <class _Func>
-#ifndef _LIBCPP_COMPILER_GCC
+#  ifndef _LIBCPP_COMPILER_GCC
   _LIBCPP_HIDE_FROM_ABI
-#endif
+#  endif
   static void __impl(__node_pointer __root, _Func& __func) {
     if (__root->__left_)
       __impl(static_cast<__node_pointer>(__root->__left_), __func);
diff --git a/libcxx/include/map b/libcxx/include/map
index 99bda5702..3be31945c 100644
--- a/libcxx/include/map
+++ b/libcxx/include/map
@@ -1440,8 +1440,8 @@ struct __specialized_algorithm<_Algorithm::__for_each, map<_Key, _Tp, _Compare,
   // set's begin() and end() are identical with and without const qualifiaction
   template <class _Map, class _Func>
   _LIBCPP_HIDE_FROM_ABI static auto operator()(_Map&& __map, _Func __func) {
-    auto [_, __func2] = __specialized_algorithm<_Algorithm::__for_each, typename __map::__base>()(
-        __map.__tree_, std::move(__func));
+    auto [_, __func2] =
+        __specialized_algorithm<_Algorithm::__for_each, typename __map::__base>()(__map.__tree_, std::move(__func));
     return std::make_pair(__map.end(), std::move(__func2));
   }
 };
@@ -2024,8 +2024,8 @@ struct __specialized_algorithm<_Algorithm::__for_each, multimap<_Key, _Tp, _Comp
   // set's begin() and end() are identical with and without const qualifiaction
   template <class _Map, class _Func>
   _LIBCPP_HIDE_FROM_ABI static auto operator()(_Map&& __map, _Func __func) {
-    auto [_, __func2] = __specialized_algorithm<_Algorithm::__for_each, typename __map::__base>()(
-        __map.__tree_, std::move(__func));
+    auto [_, __func2] =
+        __specialized_algorithm<_Algorithm::__for_each, typename __map::__base>()(__map.__tree_, std::move(__func));
     return std::make_pair(__map.end(), std::move(__func2));
   }
 };

``````````

</details>


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


More information about the libcxx-commits mailing list