[libc++] Granularize <vector> (#99705)

|                    | old time | new time |
| ------------------ | -------- | -------- |
| functional - c++23 | 416ms    | 225ms    |
| random - c++23     | 513ms    | 392ms    |
| vector - c++17     | 206ms    | 100ms    |
This commit is contained in:
Nikolas Klauser
2024-10-25 11:28:46 +02:00
committed by GitHub
parent 8be860ddc4
commit 2e43a304f1
33 changed files with 2988 additions and 2703 deletions

View File

@@ -882,6 +882,14 @@ set(files
__utility/to_underlying.h
__utility/unreachable.h
__variant/monostate.h
__vector/comparison.h
__vector/container_traits.h
__vector/erase.h
__vector/pmr.h
__vector/swap.h
__vector/vector.h
__vector/vector_bool.h
__vector/vector_bool_formatter.h
__verbose_abort
algorithm
any

View File

@@ -22,10 +22,10 @@
# include <__chrono/time_zone_link.h>
# include <__config>
# include <__memory/addressof.h>
# include <__vector/vector.h>
# include <stdexcept>
# include <string>
# include <string_view>
# include <vector>
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header

View File

@@ -22,9 +22,10 @@
#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>
#include <vector>
#if _LIBCPP_STD_VER >= 17

View File

@@ -21,6 +21,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _Alloc = allocator<_Tp> >
class _LIBCPP_TEMPLATE_VIS vector;
template <class _Allocator>
class vector<bool, _Allocator>;
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___FWD_VECTOR_H

View File

@@ -13,10 +13,11 @@
#include <__config>
#include <__random/is_valid.h>
#include <__random/uniform_real_distribution.h>
#include <__vector/vector.h>
#include <cstddef>
#include <initializer_list>
#include <iosfwd>
#include <numeric>
#include <vector>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header

View File

@@ -13,9 +13,10 @@
#include <__config>
#include <__random/is_valid.h>
#include <__random/uniform_real_distribution.h>
#include <__vector/vector.h>
#include <initializer_list>
#include <iosfwd>
#include <numeric>
#include <vector>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header

View File

@@ -13,9 +13,11 @@
#include <__config>
#include <__random/is_valid.h>
#include <__random/uniform_real_distribution.h>
#include <__vector/comparison.h>
#include <__vector/vector.h>
#include <cmath>
#include <initializer_list>
#include <iosfwd>
#include <vector>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header

View File

@@ -17,9 +17,9 @@
#include <__type_traits/enable_if.h>
#include <__type_traits/is_integral.h>
#include <__type_traits/is_unsigned.h>
#include <__vector/vector.h>
#include <cstdint>
#include <initializer_list>
#include <vector>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header

View File

@@ -0,0 +1,71 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___VECTOR_COMPARISON_H
#define _LIBCPP___VECTOR_COMPARISON_H
#include <__algorithm/equal.h>
#include <__algorithm/lexicographical_compare.h>
#include <__algorithm/lexicographical_compare_three_way.h>
#include <__compare/synth_three_way.h>
#include <__config>
#include <__fwd/vector.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _Allocator>
_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI bool
operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
return __sz == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
}
#if _LIBCPP_STD_VER <= 17
template <class _Tp, class _Allocator>
inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
return !(__x == __y);
}
template <class _Tp, class _Allocator>
inline _LIBCPP_HIDE_FROM_ABI bool operator<(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
}
template <class _Tp, class _Allocator>
inline _LIBCPP_HIDE_FROM_ABI bool operator>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
return __y < __x;
}
template <class _Tp, class _Allocator>
inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
return !(__x < __y);
}
template <class _Tp, class _Allocator>
inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
return !(__y < __x);
}
#else // _LIBCPP_STD_VER <= 17
template <class _Tp, class _Allocator>
_LIBCPP_HIDE_FROM_ABI constexpr __synth_three_way_result<_Tp>
operator<=>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
}
#endif // _LIBCPP_STD_VER <= 17
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___VECTOR_COMPARISON_H

View File

@@ -0,0 +1,39 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___VECTOR_CONTAINER_TRAITS_H
#define _LIBCPP___VECTOR_CONTAINER_TRAITS_H
#include <__config>
#include <__fwd/vector.h>
#include <__memory/allocator_traits.h>
#include <__type_traits/container_traits.h>
#include <__type_traits/disjunction.h>
#include <__type_traits/is_nothrow_constructible.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _Allocator>
struct __container_traits<vector<_Tp, _Allocator> > {
// http://eel.is/c++draft/vector.modifiers#2
// If an exception is thrown other than by the copy constructor, move constructor, assignment operator, or move
// assignment operator of T or by any InputIterator operation, there are no effects. If an exception is thrown while
// inserting a single element at the end and T is Cpp17CopyInsertable or is_nothrow_move_constructible_v<T> is true,
// there are no effects. Otherwise, if an exception is thrown by the move constructor of a non-Cpp17CopyInsertable T,
// the effects are unspecified.
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
_Or<is_nothrow_move_constructible<_Tp>, __is_cpp17_copy_insertable<_Allocator> >::value;
};
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___VECTOR_CONTAINER_TRAITS_H

View File

@@ -0,0 +1,50 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___VECTOR_ERASE_H
#define _LIBCPP___VECTOR_ERASE_H
#include <__algorithm/remove.h>
#include <__algorithm/remove_if.h>
#include <__config>
#include <__fwd/vector.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include <__undef_macros>
#if _LIBCPP_STD_VER >= 20
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _Allocator, class _Up>
_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
erase(vector<_Tp, _Allocator>& __c, const _Up& __v) {
auto __old_size = __c.size();
__c.erase(std::remove(__c.begin(), __c.end(), __v), __c.end());
return __old_size - __c.size();
}
template <class _Tp, class _Allocator, class _Predicate>
_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
erase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) {
auto __old_size = __c.size();
__c.erase(std::remove_if(__c.begin(), __c.end(), __pred), __c.end());
return __old_size - __c.size();
}
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 20
_LIBCPP_POP_MACROS
#endif // _LIBCPP___VECTOR_ERASE_H

View File

@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___VECTOR_PMR_H
#define _LIBCPP___VECTOR_PMR_H
#include <__config>
#include <__fwd/vector.h>
#include <__memory_resource/polymorphic_allocator.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
#if _LIBCPP_STD_VER >= 17
_LIBCPP_BEGIN_NAMESPACE_STD
namespace pmr {
template <class _ValueT>
using vector _LIBCPP_AVAILABILITY_PMR = std::vector<_ValueT, polymorphic_allocator<_ValueT>>;
} // namespace pmr
_LIBCPP_END_NAMESPACE_STD
#endif
#endif // _LIBCPP___VECTOR_PMR_H

View File

@@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___VECTOR_SWAP_H
#define _LIBCPP___VECTOR_SWAP_H
#include <__config>
#include <__fwd/vector.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _Allocator>
_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void
swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
__x.swap(__y);
}
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___VECTOR_SWAP_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,49 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___VECTOR_VECTOR_BOOL_FORMATTER_H
#define _LIBCPP___VECTOR_VECTOR_BOOL_FORMATTER_H
#include <__concepts/same_as.h>
#include <__config>
#include <__format/formatter.h>
#include <__format/formatter_bool.h>
#include <__fwd/vector.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
#if _LIBCPP_STD_VER >= 23
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _CharT>
// Since is-vector-bool-reference is only used once it's inlined here.
requires same_as<typename _Tp::__container, vector<bool, typename _Tp::__container::allocator_type>>
struct _LIBCPP_TEMPLATE_VIS formatter<_Tp, _CharT> {
private:
formatter<bool, _CharT> __underlying_;
public:
template <class _ParseContext>
_LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
return __underlying_.parse(__ctx);
}
template <class _FormatContext>
_LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(const _Tp& __ref, _FormatContext& __ctx) const {
return __underlying_.format(__ref, __ctx);
}
};
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 23
#endif // _LIBCPP___VECTOR_VECTOR_BOOL_FORMATTER_H

View File

@@ -1009,6 +1009,7 @@ constexpr chrono::year operator ""y(unsigned lo
# include <forward_list>
# include <string>
# include <tuple>
# include <vector>
#endif
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER == 20

View File

@@ -578,7 +578,6 @@ POLICY: For non-variadic implementations, the number of arguments is limited
# include <array>
# include <initializer_list>
# include <unordered_map>
# include <vector>
#endif
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
@@ -593,6 +592,7 @@ POLICY: For non-variadic implementations, the number of arguments is limited
# include <type_traits>
# include <typeinfo>
# include <utility>
# include <vector>
#endif
#endif // _LIBCPP_FUNCTIONAL

View File

@@ -1523,6 +1523,7 @@ module std [system] {
}
module uninitialized_algorithms {
header "__memory/uninitialized_algorithms.h"
export std.utility.pair
}
module unique_ptr {
header "__memory/unique_ptr.h"
@@ -2006,7 +2007,39 @@ module std [system] {
}
module vector {
module fwd { header "__fwd/vector.h" }
module fwd { header "__fwd/vector.h" }
module comparison { header "__vector/comparison.h" }
module container_traits { header "__vector/container_traits.h" }
module erase { header "__vector/erase.h" }
module vector_bool_formatter {
header "__vector/vector_bool_formatter.h"
export std.format.formatter
}
module pmr {
header "__vector/pmr.h"
export std.memory_resource.polymorphic_allocator
}
module swap { header "__vector/swap.h" }
module vector_bool {
header "__vector/vector_bool.h"
export std.bit_reference
export std.memory.allocator
export std.vector.comparison
export std.vector.fwd
export std.vector.swap
}
module vector {
header "__vector/vector.h"
export std.iterator.bounded_iter
export std.iterator.wrap_iter
export std.memory.allocator
export std.vector.comparison
export std.vector.fwd
export std.vector.swap
}
header "vector"
export *

File diff suppressed because it is too large Load Diff

View File

@@ -8,8 +8,8 @@
// UNSUPPORTED: libcpp-abi-no-compressed-pair-padding
#include <vector>
#include <cstdint>
#include <vector>
#include "min_allocator.h"
#include "test_allocator.h"

View File

@@ -12,10 +12,9 @@
// template <typename _Alloc>
// void __swap_allocator(_Alloc& __a1, _Alloc& __a2);
#include <__memory/swap_allocator.h>
#include <cassert>
#include <memory>
// Transitively includes `swap_allocator.h` (directly including it breaks the modules build).
#include <vector>
#include <utility>
#include "test_macros.h"

View File

@@ -145,7 +145,6 @@ chrono string
chrono string_view
chrono tuple
chrono typeinfo
chrono vector
chrono version
cinttypes cstdint
cmath limits
@@ -457,29 +456,20 @@ fstream typeinfo
fstream version
functional array
functional cctype
functional cerrno
functional climits
functional clocale
functional compare
functional cstddef
functional cstdint
functional cstdio
functional cstdlib
functional cstring
functional cwchar
functional cwctype
functional initializer_list
functional iosfwd
functional limits
functional new
functional optional
functional stdexcept
functional string
functional string_view
functional tuple
functional typeinfo
functional unordered_map
functional vector
functional version
future array
future atomic
@@ -884,17 +874,13 @@ queue tuple
queue typeinfo
queue vector
queue version
random array
random cctype
random cerrno
random climits
random clocale
random cmath
random compare
random cstddef
random cstdint
random cstdio
random cstdlib
random cstring
random ctime
random cwchar
@@ -910,8 +896,6 @@ random stdexcept
random string
random string_view
random tuple
random typeinfo
random vector
random version
ranges cctype
ranges compare
1 algorithm cctype
145 chrono string_view
146 chrono tuple
147 chrono typeinfo
chrono vector
148 chrono version
149 cinttypes cstdint
150 cmath limits
456 fstream version
457 functional array
458 functional cctype
functional cerrno
functional climits
functional clocale
459 functional compare
460 functional cstddef
461 functional cstdint
functional cstdio
functional cstdlib
462 functional cstring
463 functional cwchar
464 functional cwctype
465 functional initializer_list
functional iosfwd
466 functional limits
467 functional new
468 functional optional
469 functional stdexcept
functional string
functional string_view
470 functional tuple
471 functional typeinfo
472 functional unordered_map
functional vector
473 functional version
474 future array
475 future atomic
874 queue typeinfo
875 queue vector
876 queue version
random array
877 random cctype
random cerrno
878 random climits
random clocale
879 random cmath
880 random compare
881 random cstddef
882 random cstdint
883 random cstdio
random cstdlib
884 random cstring
885 random ctime
886 random cwchar
896 random string
897 random string_view
898 random tuple
random typeinfo
random vector
899 random version
900 ranges cctype
901 ranges compare

View File

@@ -145,7 +145,6 @@ chrono string
chrono string_view
chrono tuple
chrono typeinfo
chrono vector
chrono version
cinttypes cstdint
cmath limits
@@ -456,29 +455,20 @@ fstream typeinfo
fstream version
functional array
functional cctype
functional cerrno
functional climits
functional clocale
functional compare
functional cstddef
functional cstdint
functional cstdio
functional cstdlib
functional cstring
functional cwchar
functional cwctype
functional initializer_list
functional iosfwd
functional limits
functional new
functional optional
functional stdexcept
functional string
functional string_view
functional tuple
functional typeinfo
functional unordered_map
functional vector
functional version
future array
future atomic
@@ -883,17 +873,13 @@ queue tuple
queue typeinfo
queue vector
queue version
random array
random cctype
random cerrno
random climits
random clocale
random cmath
random compare
random cstddef
random cstdint
random cstdio
random cstdlib
random cstring
random ctime
random cwchar
@@ -909,8 +895,6 @@ random stdexcept
random string
random string_view
random tuple
random typeinfo
random vector
random version
ranges cctype
ranges compare
1 algorithm cctype
145 chrono string_view
146 chrono tuple
147 chrono typeinfo
chrono vector
148 chrono version
149 cinttypes cstdint
150 cmath limits
455 fstream version
456 functional array
457 functional cctype
functional cerrno
functional climits
functional clocale
458 functional compare
459 functional cstddef
460 functional cstdint
functional cstdio
functional cstdlib
461 functional cstring
462 functional cwchar
463 functional cwctype
464 functional initializer_list
functional iosfwd
465 functional limits
466 functional new
467 functional optional
468 functional stdexcept
functional string
functional string_view
469 functional tuple
470 functional typeinfo
471 functional unordered_map
functional vector
472 functional version
473 future array
474 future atomic
873 queue typeinfo
874 queue vector
875 queue version
random array
876 random cctype
random cerrno
877 random climits
random clocale
878 random cmath
879 random compare
880 random cstddef
881 random cstdint
882 random cstdio
random cstdlib
883 random cstring
884 random ctime
885 random cwchar
895 random string
896 random string_view
897 random tuple
random typeinfo
random vector
898 random version
899 ranges cctype
900 ranges compare

View File

@@ -13,6 +13,7 @@
#include <atomic>
#include <cassert>
#include <concepts>
#include <type_traits>
#include "atomic_helpers.h"

View File

@@ -22,6 +22,7 @@
#include <cassert>
#include <shared_mutex>
#include <thread>
#include <type_traits>
#include <vector>
#include "make_test_thread.h"

View File

@@ -21,9 +21,10 @@
// ...
// };
#include <cassert>
#include <chrono>
#include <concepts>
#include <cassert>
#include <type_traits>
#include "test_chrono_leap_second.h"

View File

@@ -20,6 +20,7 @@
#include <cassert>
#include <chrono>
#include <concepts>
#include "test_macros.h"

View File

@@ -20,6 +20,7 @@
#include <cassert>
#include <chrono>
#include <concepts>
#include "test_macros.h"

View File

@@ -20,6 +20,7 @@
#include <cassert>
#include <chrono>
#include <concepts>
#include "test_macros.h"

View File

@@ -20,6 +20,7 @@
#include <cassert>
#include <chrono>
#include <concepts>
#include "test_macros.h"

View File

@@ -18,8 +18,8 @@
// static const time_zone* default_zone();
#include <chrono>
#include <cassert>
#include <chrono>
#include <concepts>
int main(int, char**) {

View File

@@ -12,8 +12,9 @@
// test op*()
#include <memory>
#include <cassert>
#include <memory>
#include <utility>
#include <vector>
#include "test_macros.h"