mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 13:43:45 +03:00
AK: Make RedBlackTree::try_insert() return ErrorOr<void> instead of bool
This commit is contained in:
parent
b285323d91
commit
0f22ba5bf2
Notes:
sideshowbarker
2024-07-18 01:00:49 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/0f22ba5bf2a
@ -7,6 +7,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <AK/Concepts.h>
|
||||
#include <AK/Error.h>
|
||||
#include <AK/Noncopyable.h>
|
||||
#include <AK/kmalloc.h>
|
||||
|
||||
@ -453,19 +454,18 @@ public:
|
||||
insert(key, V(value));
|
||||
}
|
||||
|
||||
[[nodiscard]] bool try_insert(K key, V&& value)
|
||||
ErrorOr<void> try_insert(K key, V&& value)
|
||||
{
|
||||
auto* node = new (nothrow) Node(key, move(value));
|
||||
if (!node)
|
||||
return false;
|
||||
return Error::from_errno(ENOMEM);
|
||||
BaseTree::insert(node);
|
||||
return true;
|
||||
return {};
|
||||
}
|
||||
|
||||
void insert(K key, V&& value)
|
||||
{
|
||||
auto success = try_insert(key, move(value));
|
||||
VERIFY(success);
|
||||
MUST(try_insert(key, move(value)));
|
||||
}
|
||||
|
||||
using Iterator = RedBlackTreeIterator<RedBlackTree, V>;
|
||||
|
@ -267,8 +267,7 @@ ErrorOr<Region*> AddressSpace::add_region(NonnullOwnPtr<Region> region)
|
||||
{
|
||||
auto* ptr = region.ptr();
|
||||
SpinlockLocker lock(m_lock);
|
||||
if (!m_regions.try_insert(region->vaddr().get(), move(region)))
|
||||
return ENOMEM;
|
||||
TRY(m_regions.try_insert(region->vaddr().get(), move(region)));
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user