[libcxx-commits] [libcxx] [libcxx] adds `__split_buffer::__swap_layouts` (PR #180102)
Christopher Di Bella via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Feb 5 18:16:50 PST 2026
https://github.com/cjdb created https://github.com/llvm/llvm-project/pull/180102
This commit simplifies the cumbersome process of swapping the respective layout members for `__split_buffer` and `vector`.
>From 3fa1dcc1d510618798ed01e207e65dfd98da2d11 Mon Sep 17 00:00:00 2001
From: Christopher Di Bella <cjdb at google.com>
Date: Fri, 6 Feb 2026 01:02:43 +0000
Subject: [PATCH] [libcxx] adds `__split_buffer::__swap_layouts`
This commit simplifies the cumbersome process of swapping the
respective layout members for `__split_buffer` and `vector`.
---
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 b5d49e20dc875..9c83274e0e0d9 100644
--- a/libcxx/include/__vector/vector.h
+++ b/libcxx/include/__vector/vector.h
@@ -822,22 +822,9 @@ class vector {
return __p;
}
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __swap_layouts(__split_buffer<_Tp, allocator_type>& __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