From acc7f0ce5cc7ca6a0b428e7d0f9995c833432f97 Mon Sep 17 00:00:00 2001 From: joaquintides Date: Sat, 15 Oct 2022 11:05:51 +0200 Subject: [PATCH] refactored table_arrays dummy groups handling --- include/boost/unordered/detail/foa.hpp | 30 +++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/include/boost/unordered/detail/foa.hpp b/include/boost/unordered/detail/foa.hpp index 3b8eeed6..d875ac7b 100644 --- a/include/boost/unordered/detail/foa.hpp +++ b/include/boost/unordered/detail/foa.hpp @@ -815,6 +815,23 @@ private: * allocators. */ +template +Group* dummy_groups() +{ + /* Dummy storage initialized as if in an empty container. We make + * table_arrays::groups point to this for empty containers, so that find() + * etc. can be implemented without checking groups==nullptr. This space won't + * ever be used for insertion as container capacity is properly tuned to + * avoid that. + */ + + static constexpr typename Group::dummy_group_type + storage[Size]={typename Group::dummy_group_type(),}; + + return reinterpret_cast( + const_cast(storage)); +} + template struct table_arrays { @@ -834,18 +851,7 @@ struct table_arrays table_arrays arrays{groups_size_index,groups_size-1,nullptr,nullptr}; if(!n){ - /* We make groups point to dummy storage initialized as if in an empty - * container. This allows us to implement find() etc. without checking - * groups==nullptr. This space won't ever be used for insertion as - * container capacity is properly tuned to avoid that. - */ - - static constexpr typename group_type::dummy_group_type - storage[size_policy::min_size()]= - {typename group_type::dummy_group_type(),}; - - arrays.groups=reinterpret_cast( - const_cast(storage)); + arrays.groups=dummy_groups(); } else{ arrays.elements=