AK: Make RedBlackTree::try_insert() return ErrorOr<void> instead of bool

This commit is contained in:
Andreas Kling 2021-11-17 15:44:58 +01:00
parent b285323d91
commit 0f22ba5bf2
Notes: sideshowbarker 2024-07-18 01:00:49 +09:00
2 changed files with 6 additions and 7 deletions

View file

@ -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>;

View file

@ -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;
}