From 0bc4f2c4b951d033fc287a1104b777daeca78068 Mon Sep 17 00:00:00 2001 From: joaquintides Date: Wed, 26 Apr 2023 13:39:38 +0200 Subject: [PATCH] refactored foa::concurrent_table::merge internals --- .../unordered/detail/foa/concurrent_table.hpp | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/include/boost/unordered/detail/foa/concurrent_table.hpp b/include/boost/unordered/detail/foa/concurrent_table.hpp index 0d7272eb..d5e877cc 100644 --- a/include/boost/unordered/detail/foa/concurrent_table.hpp +++ b/include/boost/unordered/detail/foa/concurrent_table.hpp @@ -1043,13 +1043,21 @@ private: template BOOST_FORCEINLINE bool unprotected_emplace(Args&&... args) { + const auto &k=this->key_from(std::forward(args)...); + auto hash=this->hash_for(k); + auto pos0=this->position_for(hash); + // TODO: could be made more efficient (nonconcurrent scenario) - for(;;){ - int res=unprotected_norehash_emplace_or_visit( - group_shared{},[](const value_type&){},std::forward(args)...); - if(BOOST_LIKELY(res>=0))return res!=0; - unprotected_rehash_if_full(); + if(unprotected_visit( + group_shared{},k,pos0,hash,[](const value_type&){}))return false; + + if(BOOST_LIKELY(this->size_ml)){ + this->unchecked_emplace_at(pos0,hash,std::forward(args)...); } + else{ + this->unchecked_emplace_with_rehash(hash,std::forward(args)...); + } + return true; } struct reserve_size @@ -1098,9 +1106,9 @@ private: unprotected_norehash_emplace_or_visit( GroupAccessMode access_mode,F&& f,Args&&... args) { - const auto &k=this->key_from(std::forward(args)...); - auto hash=this->hash_for(k); - auto pos0=this->position_for(hash); + const auto &k=this->key_from(std::forward(args)...); + auto hash=this->hash_for(k); + auto pos0=this->position_for(hash); for(;;){ startover: