[libcxx-commits] [libcxx] 65f39a1 - [libcxx] Add `__split_buffer::__swap_layouts` (#180102)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Mar 6 13:57:08 PST 2026
Author: Christopher Di Bella
Date: 2026-03-06T21:57:03Z
New Revision: 65f39a16abf651008185839459fb330258800a62
URL: https://github.com/llvm/llvm-project/commit/65f39a16abf651008185839459fb330258800a62
DIFF: https://github.com/llvm/llvm-project/commit/65f39a16abf651008185839459fb330258800a62.diff
LOG: [libcxx] Add `__split_buffer::__swap_layouts` (#180102)
This commit simplifies the cumbersome process of swapping the respective
layout members for `__split_buffer` and `vector`.
Added:
Modified:
libcxx/include/__split_buffer
libcxx/include/__vector/vector.h
Removed:
################################################################################
diff --git a/libcxx/include/__split_buffer b/libcxx/include/__split_buffer
index 89c398e525998..27ec8b7f988d3 100644
--- a/libcxx/include/__split_buffer
+++ b/libcxx/include/__split_buffer
@@ -188,6 +188,14 @@ public:
__back_cap_ = __other.__back_cap_;
}
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
+ __swap_layouts(pointer& __begin, pointer& __end, pointer& __back_capacity) {
+ using std::swap;
+ swap(__begin_, __begin);
+ swap(__end_, __end);
+ swap(__back_cap_, __back_capacity);
+ }
+
private:
pointer __front_cap_ = nullptr;
pointer __begin_ = nullptr;
@@ -336,6 +344,14 @@ public:
__size_ = __other.__size_;
}
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
+ __swap_layouts(pointer& __begin, size_type& __size, size_type& __capacity) {
+ using std::swap;
+ swap(__begin_, __begin);
+ swap(__size_, __size);
+ swap(__cap_, __capacity);
+ }
+
private:
pointer __front_cap_ = nullptr;
pointer __begin_ = nullptr;
@@ -447,6 +463,7 @@ public:
using __base_type::__set_data;
using __base_type::__set_sentinel;
using __base_type::__set_valid_range;
+ using __base_type::__swap_layouts;
using typename __base_type::__alloc_traits;
using typename __base_type::allocator_type;
diff --git a/libcxx/include/__vector/vector.h b/libcxx/include/__vector/vector.h
index 181230df819ea..22b4f7005a208 100644
--- a/libcxx/include/__vector/vector.h
+++ b/libcxx/include/__vector/vector.h
@@ -820,22 +820,9 @@ class vector {
return __p;
}
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __swap_layouts(_SplitBuffer& __sb) {
- auto __vector_begin = __begin_;
- auto __vector_sentinel = __end_;
- auto __vector_cap = __cap_;
-
- auto __sb_begin = __sb.begin();
- auto __sb_sentinel = __sb.__raw_sentinel();
- auto __sb_cap = __sb.__raw_capacity();
-
- // TODO: replace with __set_valid_range and __set_capacity when vector supports it.
- __begin_ = __sb_begin;
- __end_ = __sb_sentinel;
- __cap_ = __sb_cap;
-
- __sb.__set_valid_range(__vector_begin, __vector_sentinel);
- __sb.__set_capacity(__vector_cap);
+ _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
+ __swap_layouts(__split_buffer<_Tp, allocator_type>& __sb) {
+ __sb.__swap_layouts(__begin_, __end_, __cap_);
}
};
More information about the libcxx-commits
mailing list