From e2b61dd6da35ac47fba7007b0ecae344dc0d08fe Mon Sep 17 00:00:00 2001 From: Susan Hinrichs Date: Mon, 17 May 2021 20:07:18 +0000 Subject: [PATCH 1/2] Remove bucket search from IntrusiveHashMap::erase --- include/tscore/IntrusiveHashMap.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/include/tscore/IntrusiveHashMap.h b/include/tscore/IntrusiveHashMap.h index f8dd340aff2..11141c39758 100644 --- a/include/tscore/IntrusiveHashMap.h +++ b/include/tscore/IntrusiveHashMap.h @@ -578,14 +578,23 @@ IntrusiveHashMap::erase(iterator const &loc) -> iterator template bool -IntrusiveHashMap::erase(value_type *value) +IntrusiveHashMap::erase(value_type *v) { - auto loc = this->find(value); - if (loc != this->end()) { - this->erase(loc); - return true; + ++(this->iterator_for(v)); // get around no const_iterator -> iterator. + Bucket *b = this->bucket_for(H::key_of(v)); + value_type *nv = H::next_ptr(v); + value_type *limit = b->limit(); + if (b->_v == v) { // removed first element in bucket, update bucket + if (limit == nv) { // that was also the only element, deactivate bucket + _active_buckets.erase(b); + b->clear(); + } else { + b->_v = nv; + --b->_count; + } } - return false; + _list.erase(v); + return true; } template From 6e46c3db92fc698df972522946c7ff45411711f5 Mon Sep 17 00:00:00 2001 From: Susan Hinrichs Date: Tue, 25 May 2021 20:49:10 +0000 Subject: [PATCH 2/2] Make erase call the other one --- include/tscore/IntrusiveHashMap.h | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/include/tscore/IntrusiveHashMap.h b/include/tscore/IntrusiveHashMap.h index 11141c39758..83bad931b71 100644 --- a/include/tscore/IntrusiveHashMap.h +++ b/include/tscore/IntrusiveHashMap.h @@ -580,21 +580,12 @@ template bool IntrusiveHashMap::erase(value_type *v) { - ++(this->iterator_for(v)); // get around no const_iterator -> iterator. - Bucket *b = this->bucket_for(H::key_of(v)); - value_type *nv = H::next_ptr(v); - value_type *limit = b->limit(); - if (b->_v == v) { // removed first element in bucket, update bucket - if (limit == nv) { // that was also the only element, deactivate bucket - _active_buckets.erase(b); - b->clear(); - } else { - b->_v = nv; - --b->_count; - } + auto loc = this->iterator_for(v); + if (loc != this->end()) { + this->erase(loc); + return true; } - _list.erase(v); - return true; + return false; } template