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

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 18 08:56:56 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

<details>
<summary>Changes</summary>

`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 the `boyer_moore_searcher` constructor from 26ms to 22ms on my machine.


---
Full diff: https://github.com/llvm/llvm-project/pull/144310.diff


1 Files Affected:

- (modified) libcxx/include/__functional/boyer_moore_searcher.h (+1-3) 


``````````diff
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)

``````````

</details>


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


More information about the libcxx-commits mailing list