[libcxx-commits] [libcxx] [libc++][WIP] use linear search instead of binary search for small flat_map (PR #211794)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 24 06:48:50 PDT 2026


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/__flat_map/flat_map.h libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.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/__flat_map/flat_map.h b/libcxx/include/__flat_map/flat_map.h
index 8b15491a6..0e3f581b8 100644
--- a/libcxx/include/__flat_map/flat_map.h
+++ b/libcxx/include/__flat_map/flat_map.h
@@ -991,7 +991,7 @@ private:
 
   template <class _Self, class _Kp>
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static auto __find_impl(_Self&& __self, const _Kp& __key) {
-    auto __key_iter = std::ranges::find(__self.__containers_.keys, __key);
+    auto __key_iter    = std::ranges::find(__self.__containers_.keys, __key);
     auto __mapped_iter = __corresponding_mapped_it(__self, __key_iter);
 
     using Res = std::conditional_t<std::is_const_v<std::remove_reference_t<_Self>>, const_iterator, iterator>;
diff --git a/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h b/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h
index 93d06a020..411b24fbc 100644
--- a/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h
+++ b/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h
@@ -66,7 +66,14 @@ void associative_container_benchmarks(std::string container) {
     benchmark::RegisterBenchmark(container + "::" + operation, f)->Arg(0)->Arg(32)->Arg(1024)->Arg(8192);
   };
   auto bench_non_empty = [&](std::string operation, auto f) {
-    benchmark::RegisterBenchmark(container + "::" + operation, f)->Arg(1)->Arg(4)->Arg(8)->Arg(16)->Arg(32)->Arg(1024)->Arg(8192);
+    benchmark::RegisterBenchmark(container + "::" + operation, f)
+        ->Arg(1)
+        ->Arg(4)
+        ->Arg(8)
+        ->Arg(16)
+        ->Arg(32)
+        ->Arg(1024)
+        ->Arg(8192);
   };
 
   static constexpr bool is_multi_key_container =
@@ -693,15 +700,15 @@ void associative_container_benchmarks(std::string container) {
       std::vector<Value> in  = make_value_types(generate_unique_keys(size));
       Container c(in.begin(), in.end());
       std::vector<Key> keys;
-      for(size_t i = 0; i <in.size(); ++i) {
+      for (size_t i = 0; i < in.size(); ++i) {
         keys.push_back(get_key(in[getRandomEngine()() % in.size()]));
       }
       size_t i = 0;
 
       for (auto _ : st) {
-      //st.PauseTiming();
-      const auto& key =  keys[++i%keys.size()];
-      //st.ResumeTiming();
+        //st.PauseTiming();
+        const auto& key = keys[++i % keys.size()];
+        //st.ResumeTiming();
         auto result = func(c, key);
         benchmark::DoNotOptimize(c);
         benchmark::DoNotOptimize(result);

``````````

</details>


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


More information about the libcxx-commits mailing list