stylistic

This commit is contained in:
joaquintides
2022-10-18 18:35:41 +02:00
parent 64cb43ce32
commit d13a9dcaaf

View File

@ -1151,8 +1151,8 @@ public:
(void)c; /* unused var warning */ (void)c; /* unused var warning */
/* This works because subsequent x.clear() does not depend on the /* This works because subsequent x.clear() does not depend on the
* elements' values. * elements' values.
*/ */
x.for_all_elements([this](value_type* p){ x.for_all_elements([this](value_type* p){
unchecked_insert(type_policy::move(*p)); unchecked_insert(type_policy::move(*p));
}); });
@ -1631,25 +1631,22 @@ private:
BOOST_NOINLINE void unchecked_rehash(std::size_t n) BOOST_NOINLINE void unchecked_rehash(std::size_t n)
{ {
auto new_arrays_=new_arrays(n); auto new_arrays_=new_arrays(n);
std::size_t num_tx=0; std::size_t num_destroyed=0;
BOOST_TRY{ BOOST_TRY{
for_all_elements([&,this](value_type* p){ for_all_elements([&,this](value_type* p){
/* We increment num_tx *before* actual transfer to guard us against ++num_destroyed; /* p destroyed below even if an exception is thrown */
* exceptions thrown in the middle of value move construction.
*/
++num_tx;
nosize_transfer_element(p,new_arrays_); nosize_transfer_element(p,new_arrays_);
}); });
} }
BOOST_CATCH(...){ BOOST_CATCH(...){
if(num_tx){ if(num_destroyed){
size_-=num_tx; size_-=num_destroyed;
for(auto pg=arrays.groups;;++pg){ for(auto pg=arrays.groups;;++pg){
auto mask=pg->match_occupied(); auto mask=pg->match_occupied();
while(mask){ while(mask){
auto nz=unchecked_countr_zero(mask); auto nz=unchecked_countr_zero(mask);
pg->reset(nz); pg->reset(nz);
if(!(--num_tx))goto continue_; if(!(--num_destroyed))goto continue_;
mask&=mask-1; mask&=mask-1;
} }
} }
@ -1694,8 +1691,11 @@ private:
void nosize_transfer_element(value_type* p,const arrays_type& arrays_) void nosize_transfer_element(value_type* p,const arrays_type& arrays_)
{ {
/* Destroy p always to guard us against an exception in the middle of value
* move construction, which could leave the source half-moved.
*/
destroy_on_exit d{this,p}; destroy_on_exit d{this,p};
(void)d; /* ununsed var warning */ (void)d; /* unused var warning */
auto hash=hash_for(key_from(*p)); auto hash=hash_for(key_from(*p));
nosize_unchecked_emplace_at( nosize_unchecked_emplace_at(
arrays_,position_for(hash,arrays_),hash,type_policy::move(*p)); arrays_,position_for(hash,arrays_),hash,type_policy::move(*p));