diff --git a/AK/HashMap.h b/AK/HashMap.h index ca7f73c76ed..7691ca165ac 100644 --- a/AK/HashMap.h +++ b/AK/HashMap.h @@ -39,8 +39,8 @@ public: HashMap(std::initializer_list list) { MUST(try_ensure_capacity(list.size())); - for (auto& item : list) - set(item.key, item.value); + for (auto& [key, value] : list) + set(key, value); } HashMap(HashMap const&) = default; // FIXME: Not OOM-safe! Use clone() instead. @@ -274,16 +274,16 @@ public: { Vector list; list.ensure_capacity(size()); - for (auto& it : *this) - list.unchecked_append(it.key); + for (auto const& [key, _] : *this) + list.unchecked_append(key); return list; } [[nodiscard]] u32 hash() const { u32 hash = 0; - for (auto& it : *this) { - auto entry_hash = pair_int_hash(it.key.hash(), it.value.hash()); + for (auto const& [key, value] : *this) { + auto entry_hash = pair_int_hash(key.hash(), value.hash()); hash = pair_int_hash(hash, entry_hash); } return hash; @@ -293,8 +293,9 @@ public: ErrorOr> clone() const { HashMap hash_map_clone; - for (auto& it : *this) - TRY(hash_map_clone.try_set(it.key, it.value)); + TRY(hash_map_clone.try_ensure_capacity(size())); + for (auto const& [key, value] : *this) + hash_map_clone.set(key, value); return hash_map_clone; }