mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Expose RedBlackTree allocation failures via try_insert
This should help with using the RedBlackTree in a more OOM-safe way in the kernel.
This commit is contained in:
parent
a9a54914bf
commit
e94dfb7355
Notes:
sideshowbarker
2024-07-18 09:00:48 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/e94dfb7355b Pull-request: https://github.com/SerenityOS/serenity/pull/8758
1 changed files with 11 additions and 2 deletions
|
@ -446,10 +446,19 @@ public:
|
|||
insert(key, V(value));
|
||||
}
|
||||
|
||||
[[nodiscard]] bool try_insert(K key, V&& value)
|
||||
{
|
||||
auto* node = new (nothrow) Node(key, move(value));
|
||||
if (!node)
|
||||
return false;
|
||||
BaseTree::insert(node);
|
||||
return true;
|
||||
}
|
||||
|
||||
void insert(K key, V&& value)
|
||||
{
|
||||
auto* node = new Node(key, move(value));
|
||||
BaseTree::insert(node);
|
||||
auto success = try_insert(key, move(value));
|
||||
VERIFY(success);
|
||||
}
|
||||
|
||||
using Iterator = RedBlackTreeIterator<RedBlackTree, V>;
|
||||
|
|
Loading…
Reference in a new issue