Skip to content

Commit 3ee0f97

Browse files
authored
[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.
1 parent b173c12 commit 3ee0f97

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

libcxx/include/__functional/boyer_moore_searcher.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
#include <__config>
1818
#include <__functional/hash.h>
1919
#include <__functional/operations.h>
20-
#include <__iterator/distance.h>
2120
#include <__iterator/iterator_traits.h>
2221
#include <__memory/shared_ptr.h>
2322
#include <__type_traits/make_unsigned.h>
2423
#include <__utility/pair.h>
25-
#include <__vector/vector.h>
2624
#include <array>
2725
#include <limits>
2826
#include <unordered_map>
@@ -196,7 +194,7 @@ class boyer_moore_searcher {
196194
if (__count == 0)
197195
return;
198196

199-
vector<difference_type> __scratch(__count);
197+
auto __scratch = std::make_unique<difference_type[]>(__count);
200198

201199
__compute_bm_prefix(__first, __last, __pred, __scratch);
202200
for (size_t __i = 0; __i <= __count; ++__i)

libcxx/include/functional

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,10 @@ POLICY: For non-variadic implementations, the number of arguments is limited
599599
# include <utility>
600600
# include <vector>
601601
# endif
602+
603+
# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER == 23
604+
# include <__vector/vector.h>
605+
# endif
602606
#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
603607

604608
#endif // _LIBCPP_FUNCTIONAL

0 commit comments

Comments
 (0)