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;