From 8c2c816cf746d70b2623412c81c50e8d96d1c13a Mon Sep 17 00:00:00 2001 From: Christopher Di Bella Date: Thu, 26 Mar 2026 10:09:34 -0700 Subject: [PATCH] Reapply "[libcxx] adds `__split_buffer::__swap_layouts`" (#185120) (#187763) 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 89c398e52599..27ec8b7f988d 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 229287b43e70..df41c102616e 100644 --- a/libcxx/include/__vector/vector.h +++ b/libcxx/include/__vector/vector.h @@ -814,22 +814,9 @@ private: 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(_SplitBuffer& __sb) { + __sb.__swap_layouts(__begin_, __end_, __cap_); } };