diff --git a/AK/HashMap.h b/AK/HashMap.h index bd2ccdd633..a01ba835d0 100644 --- a/AK/HashMap.h +++ b/AK/HashMap.h @@ -265,22 +265,17 @@ public: return take(begin()->key).release_value(); } - V& ensure(K const& key) - { - auto it = find(key); - if (it != end()) - return it->value; - auto result = set(key, V()); - VERIFY(result == HashSetResult::InsertedNewEntry); - return find(key)->value; - } - template V& ensure(K const& key, Callback initialization_callback, HashSetExistingEntryBehavior existing_entry_behavior = HashSetExistingEntryBehavior::Keep) { return m_table.ensure(KeyTraits::hash(key), [&](auto& entry) { return KeyTraits::equals(entry.key, key); }, [&] -> Entry { return { key, initialization_callback() }; }, existing_entry_behavior).value; } + V& ensure(K const& key) + { + return ensure(key, [] { return V(); }); + } + template ErrorOr try_ensure(K const& key, Callback initialization_callback) {