[libcxx-commits] [libcxx] c254a1e - [libc++][NFC] Remove vector::__base_destruct_at_end (#217631)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Aug 25 01:24:04 PDT 2026
Author: Nikolas Klauser
Date: 2026-08-25T10:23:58+02:00
New Revision: c254a1ee0d641dcddff201c71ae2dbc682d89391
URL: https://github.com/llvm/llvm-project/commit/c254a1ee0d641dcddff201c71ae2dbc682d89391
DIFF: https://github.com/llvm/llvm-project/commit/c254a1ee0d641dcddff201c71ae2dbc682d89391.diff
LOG: [libc++][NFC] Remove vector::__base_destruct_at_end (#217631)
We can just inline `__base_destruct_at_end` into `__destruct_at_end`.
The only other place where `__base_destruct_at_end` was used is
`clear()`, but that has basically the same code as `__destruct_at_end`,
so we can use `__destruct_at_end` instead.
Added:
Modified:
libcxx/include/__vector/vector.h
Removed:
################################################################################
diff --git a/libcxx/include/__vector/vector.h b/libcxx/include/__vector/vector.h
index c12fc039473fe..70e42e8204687 100644
--- a/libcxx/include/__vector/vector.h
+++ b/libcxx/include/__vector/vector.h
@@ -562,9 +562,7 @@ class _LIBCPP_WARN_UNUSED vector {
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last);
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT {
- size_type __old_size = size();
- __base_destruct_at_end(this->__layout_.__begin_ptr());
- __annotate_shrink(__old_size);
+ __destruct_at_end(__layout_.__begin_ptr());
}
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz);
@@ -717,9 +715,11 @@ class _LIBCPP_WARN_UNUSED vector {
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, false_type)
_NOEXCEPT_(__alloc_traits::is_always_equal::value);
+
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __destruct_at_end(pointer __new_last) _NOEXCEPT {
size_type __old_size = size();
- __base_destruct_at_end(__new_last);
+ std::__allocator_destroy(__layout_.__alloc(), __new_last, __layout_.__end_ptr());
+ __layout_.__set_bound_using_pointer(__new_last);
__annotate_shrink(__old_size);
}
@@ -776,13 +776,6 @@ class _LIBCPP_WARN_UNUSED vector {
_ConstructTransaction& operator=(_ConstructTransaction const&) = delete;
};
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __base_destruct_at_end(pointer __new_last) _NOEXCEPT {
- pointer __soon_to_be_end = __layout_.__end_ptr();
- while (__new_last != __soon_to_be_end)
- __alloc_traits::destroy(this->__layout_.__alloc(), std::__to_address(--__soon_to_be_end));
- __layout_.__set_bound_using_pointer(__new_last);
- }
-
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector& __c) {
__copy_assign_alloc(__c, integral_constant<bool, __alloc_traits::propagate_on_container_copy_assignment::value>());
}
More information about the libcxx-commits
mailing list