From b4efc91e7f735304f47696ffb52c3ebfdaa5c0cd Mon Sep 17 00:00:00 2001 From: Gregory Popovitch Date: Sat, 8 May 2021 07:07:50 -0400 Subject: [PATCH] use `find_as_pair` in `erase_if_impl` as well. --- parallel_hashmap/phmap.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/parallel_hashmap/phmap.h b/parallel_hashmap/phmap.h index e37774b..c725f87 100644 --- a/parallel_hashmap/phmap.h +++ b/parallel_hashmap/phmap.h @@ -3622,6 +3622,7 @@ public: // if map contains key, lambda is called with the mapped value without read lock protection, // and if_contains_unsafe returns true. This is a const API and lambda should not modify the value + // This should be used only if we know that no other thread may be mutating the map at the time. // ----------------------------------------------------------------------------------------- template bool if_contains_unsafe(const key_arg& key, F&& f) const { @@ -3702,12 +3703,11 @@ private: static_assert(std::is_invocable::value); #endif L m; - auto it = this->template find(key, this->hash(key), m); - if (it == this->end()) - return false; - if (std::forward(f)(Policy::value(&*it))) + auto res = this->template find_as_pair(key, this->hash(key), m); + if (res.second != res.first->set_.end() && + std::forward(f)(Policy::value(&*res.second))) { - this->erase(it); + res.first->set_.erase(res.second); return true; } return false;