[libcxx-commits] [libcxx] [libc++] Avoid including vector in <functional> (PR #144310)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jun 16 00:44:29 PDT 2025


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/144310

`vector` has been used in a very simple way in `boyer_moore_searcher`. We can instead just use `unique_ptr<T[]>`, which is a lot simpler, allowing us to drop the `vector` dependency while not losing any expressiveness in the code. As a nice side effect, this also reduces the time it takes to instantiate from x to y.


>From ed4adca3b75df42fcc26b5f83adc569ab0f6696d Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Mon, 16 Jun 2025 09:42:02 +0200
Subject: [PATCH] [libc++] Avoid including vector in <functional>

---
 libcxx/include/__functional/boyer_moore_searcher.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libcxx/include/__functional/boyer_moore_searcher.h b/libcxx/include/__functional/boyer_moore_searcher.h
index 7889232f4b919..88c6577f04dee 100644
--- a/libcxx/include/__functional/boyer_moore_searcher.h
+++ b/libcxx/include/__functional/boyer_moore_searcher.h
@@ -17,12 +17,10 @@
 #include <__config>
 #include <__functional/hash.h>
 #include <__functional/operations.h>
-#include <__iterator/distance.h>
 #include <__iterator/iterator_traits.h>
 #include <__memory/shared_ptr.h>
 #include <__type_traits/make_unsigned.h>
 #include <__utility/pair.h>
-#include <__vector/vector.h>
 #include <array>
 #include <limits>
 #include <unordered_map>
@@ -196,7 +194,7 @@ class boyer_moore_searcher {
     if (__count == 0)
       return;
 
-    vector<difference_type> __scratch(__count);
+    auto __scratch = std::make_unique<difference_type[]>(__count);
 
     __compute_bm_prefix(__first, __last, __pred, __scratch);
     for (size_t __i = 0; __i <= __count; ++__i)



More information about the libcxx-commits mailing list