[libcxx-commits] [libcxx] 3ee0f97 - [libc++] Avoid including vector in <functional> (#144310)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 2 12:48:33 PDT 2025
Author: Nikolas Klauser
Date: 2025-07-02T21:48:30+02:00
New Revision: 3ee0f97b950a550ef14e3adbdf45f507273f2190
URL: https://github.com/llvm/llvm-project/commit/3ee0f97b950a550ef14e3adbdf45f507273f2190
DIFF: https://github.com/llvm/llvm-project/commit/3ee0f97b950a550ef14e3adbdf45f507273f2190.diff
LOG: [libc++] Avoid including vector in <functional> (#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 the `boyer_moore_searcher` constructor from
26ms to 22ms on my machine.
Added:
Modified:
libcxx/include/__functional/boyer_moore_searcher.h
libcxx/include/functional
Removed:
################################################################################
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<
diff erence_type> __scratch(__count);
+ auto __scratch = std::make_unique<
diff erence_type[]>(__count);
__compute_bm_prefix(__first, __last, __pred, __scratch);
for (size_t __i = 0; __i <= __count; ++__i)
diff --git a/libcxx/include/functional b/libcxx/include/functional
index b121a19d6bcb3..c72d0931e4b92 100644
--- a/libcxx/include/functional
+++ b/libcxx/include/functional
@@ -599,6 +599,10 @@ POLICY: For non-variadic implementations, the number of arguments is limited
# include <utility>
# include <vector>
# endif
+
+# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER == 23
+# include <__vector/vector.h>
+# endif
#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
#endif // _LIBCPP_FUNCTIONAL
More information about the libcxx-commits
mailing list