[libcxx-commits] [libcxx] Reapply "[libcxx] adds `__split_buffer::__swap_layouts`" (#185120) (PR #187763)
Christopher Di Bella via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Mar 21 13:09:49 PDT 2026
https://github.com/cjdb updated https://github.com/llvm/llvm-project/pull/187763
>From 30e21aa93098359486bdfaf8c31ecf5ee03b43d8 Mon Sep 17 00:00:00 2001
From: Christopher Di Bella <cjdb at google.com>
Date: Fri, 20 Mar 2026 18:37:05 +0000
Subject: [PATCH 1/2] Reapply "[libcxx] adds `__split_buffer::__swap_layouts`"
(#185120)
This reverts commit 01a97050f01b6b833d3d1f22997b5009293b43a3.
---
libcxx/include/__split_buffer | 17 +++++++++++++++++
libcxx/include/__vector/vector.h | 19 +++----------------
2 files changed, 20 insertions(+), 16 deletions(-)
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 229287b43e702..60eb8b61315c0 100644
--- a/libcxx/include/__vector/vector.h
+++ b/libcxx/include/__vector/vector.h
@@ -814,22 +814,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_);
}
};
>From e33f1cf809e6c5457bf85045e3df8758f8a1362a Mon Sep 17 00:00:00 2001
From: Christopher Di Bella <cjdb at google.com>
Date: Fri, 20 Mar 2026 21:46:10 +0000
Subject: [PATCH 2/2] fixes break
---
libcxx/include/__vector/vector.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/include/__vector/vector.h b/libcxx/include/__vector/vector.h
index 60eb8b61315c0..df41c102616eb 100644
--- a/libcxx/include/__vector/vector.h
+++ b/libcxx/include/__vector/vector.h
@@ -815,7 +815,7 @@ class vector {
}
_LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
- __swap_layouts(__split_buffer<_Tp, allocator_type>& __sb) {
+ __swap_layouts(_SplitBuffer& __sb) {
__sb.__swap_layouts(__begin_, __end_, __cap_);
}
};
More information about the libcxx-commits
mailing list