mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Add function 'shallow_clone()' to HashMap
This makes a shallow clone of the HashMap, the items temselves are not cloned in any way.
This commit is contained in:
parent
3bc5fcaccc
commit
9d13537fc7
Notes:
sideshowbarker
2024-07-17 03:00:02 +09:00
Author: https://github.com/kennethmyhra Commit: https://github.com/SerenityOS/serenity/commit/9d13537fc7 Pull-request: https://github.com/SerenityOS/serenity/pull/16356 Reviewed-by: https://github.com/davidot Reviewed-by: https://github.com/linusg ✅
1 changed files with 9 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2023, Kenneth Myhra <kennethmyhra@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -280,6 +281,14 @@ public:
|
|||
return hash;
|
||||
}
|
||||
|
||||
ErrorOr<HashMap<K, V>> clone()
|
||||
{
|
||||
HashMap<K, V> hash_map_clone;
|
||||
for (auto& it : *this)
|
||||
TRY(hash_map_clone.try_set(it.key, it.value));
|
||||
return hash_map_clone;
|
||||
}
|
||||
|
||||
private:
|
||||
HashTableType m_table;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue