[libcxx-commits] [libcxx] [libc++] Fold __search_substring into _Traits::find in case the second string has length 1 (PR #160076)

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Sep 22 04:31:45 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 h,cpp -- libcxx/include/__string/char_traits.h libcxx/test/benchmarks/containers/string.bench.cpp
``````````

: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/test/benchmarks/containers/string.bench.cpp b/libcxx/test/benchmarks/containers/string.bench.cpp
index 6528ae6a0..68f596b1b 100644
--- a/libcxx/test/benchmarks/containers/string.bench.cpp
+++ b/libcxx/test/benchmarks/containers/string.bench.cpp
@@ -60,48 +60,44 @@ static void BM_StringFindMatch2(benchmark::State& state) {
 }
 BENCHMARK(BM_StringFindMatch2)->Range(1, MAX_STRING_LEN / 4);
 
-static void BM_string_literal(benchmark::State& state)
-{
-    std::string s;
+static void BM_string_literal(benchmark::State& state) {
+  std::string s;
 
-    for (int i = 0; i < state.range(0); i++)
-        s += 'a';
+  for (int i = 0; i < state.range(0); i++)
+    s += 'a';
 
-    s += 'b';
+  s += 'b';
 
-    benchmark::DoNotOptimize(s.data());
-    benchmark::ClobberMemory();
-    size_t pos;
+  benchmark::DoNotOptimize(s.data());
+  benchmark::ClobberMemory();
+  size_t pos;
 
-    for (auto _ : state)
-    {
-        benchmark::DoNotOptimize(pos = s.find("b")); // "b" is a string literal, it should be longer
-        benchmark::ClobberMemory();
-    }
+  for (auto _ : state) {
+    benchmark::DoNotOptimize(pos = s.find("b")); // "b" is a string literal, it should be longer
+    benchmark::ClobberMemory();
+  }
 }
 
-BENCHMARK(BM_string_literal)->RangeMultiplier(2)->Range(8, 8<<10);
+BENCHMARK(BM_string_literal)->RangeMultiplier(2)->Range(8, 8 << 10);
 
-static void BM_char_literal(benchmark::State& state)
-{
-    std::string s;
+static void BM_char_literal(benchmark::State& state) {
+  std::string s;
 
-    for (int i = 0; i < state.range(0); i++)
-        s += 'a';
+  for (int i = 0; i < state.range(0); i++)
+    s += 'a';
 
-    s += 'b';
+  s += 'b';
 
-    benchmark::DoNotOptimize(s.data());
-    benchmark::ClobberMemory();
-    size_t pos;
+  benchmark::DoNotOptimize(s.data());
+  benchmark::ClobberMemory();
+  size_t pos;
 
-    for (auto _ : state)
-    {
-        benchmark::DoNotOptimize(pos = s.find('b')); // 'b' is a char literal, it should be faster
-        benchmark::ClobberMemory();
-    }
+  for (auto _ : state) {
+    benchmark::DoNotOptimize(pos = s.find('b')); // 'b' is a char literal, it should be faster
+    benchmark::ClobberMemory();
+  }
 }
-BENCHMARK(BM_char_literal)->RangeMultiplier(2)->Range(8, 8<<10);
+BENCHMARK(BM_char_literal)->RangeMultiplier(2)->Range(8, 8 << 10);
 
 static void BM_StringCtorDefault(benchmark::State& state) {
   for (auto _ : state) {

``````````

</details>


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


More information about the libcxx-commits mailing list