From c673b7220a553215335fafe57144c2e7945e7797 Mon Sep 17 00:00:00 2001 From: Hendiadyoin1 Date: Wed, 15 Dec 2021 15:18:30 +0100 Subject: [PATCH] AK: Enable fast path for removal by hash-compatible key in HashMap/Table --- AK/HashMap.h | 11 +++++++++++ AK/HashTable.h | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/AK/HashMap.h b/AK/HashMap.h index 78a307e3ee..33251fde72 100644 --- a/AK/HashMap.h +++ b/AK/HashMap.h @@ -63,6 +63,17 @@ public: return false; } + template Key> + requires(IsSame>) bool remove(Key const& key) + { + auto it = find(key); + if (it != end()) { + m_table.remove(it); + return true; + } + return false; + } + using HashTableType = HashTable; using IteratorType = typename HashTableType::Iterator; using ConstIteratorType = typename HashTableType::ConstIterator; diff --git a/AK/HashTable.h b/AK/HashTable.h index 5be70d5735..cacd4bda42 100644 --- a/AK/HashTable.h +++ b/AK/HashTable.h @@ -373,6 +373,17 @@ public: return false; } + template K> + requires(IsSame>) bool remove(K const& value) + { + auto it = find(value); + if (it != end()) { + remove(it); + return true; + } + return false; + } + void remove(Iterator iterator) { VERIFY(iterator.m_bucket);