From a91efeb23729c1b088e65ebbd75e65b0c54d441d Mon Sep 17 00:00:00 2001 From: joaquintides Date: Thu, 20 Apr 2023 17:29:21 +0200 Subject: [PATCH] refactored size_/ml swap --- include/boost/unordered/detail/foa/core.hpp | 31 ++++++++++----------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/include/boost/unordered/detail/foa/core.hpp b/include/boost/unordered/detail/foa/core.hpp index 5e07151b..34b4bb3d 100644 --- a/include/boost/unordered/detail/foa/core.hpp +++ b/include/boost/unordered/detail/foa/core.hpp @@ -1226,6 +1226,7 @@ public: using alloc_traits=boost::allocator_traits; using element_type=typename type_policy::element_type; using arrays_type=Arrays; + using size_impl_type=SizeImpl; using key_type=typename type_policy::key_type; using init_type=typename type_policy::init_type; @@ -1281,20 +1282,8 @@ public: { if(al()==x.al()){ std::swap(arrays,x.arrays); - - // when SizeImpl is an atomic type, std::swap() can't be used - // as it's not MoveConstructible so we instead opt for this manual version - { - std::size_t tmp{size_}; - size_=static_cast(x.size_); - x.size_=tmp; - } - - { - std::size_t tmp{ml}; - ml=static_cast(x.ml); - x.ml=tmp; - } + swap_size_impl(size_,x.size_); + swap_size_impl(ml,x.ml); } else{ reserve(x.size()); @@ -1708,9 +1697,9 @@ public: } } - arrays_type arrays; - SizeImpl ml; - SizeImpl size_; + arrays_type arrays; + size_impl_type ml; + size_impl_type size_; private: template< @@ -1875,6 +1864,14 @@ private: } } + static inline void swap_size_impl(size_impl_type& x,size_impl_type& y) + { + /* std::swap can't be used on non-assignable atomics */ + std::size_t tmp=x; + x=static_cast(y); + y=tmp; + } + void recover_slot(unsigned char* pc) { /* If this slot potentially caused overflow, we decrease the maximum load so