mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-29 06:02:07 +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
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Concepts.h>
|
#include <AK/Concepts.h>
|
||||||
|
#include <AK/Error.h>
|
||||||
#include <AK/Noncopyable.h>
|
#include <AK/Noncopyable.h>
|
||||||
#include <AK/kmalloc.h>
|
#include <AK/kmalloc.h>
|
||||||
|
|
||||||
@ -453,19 +454,18 @@ public:
|
|||||||
insert(key, V(value));
|
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));
|
auto* node = new (nothrow) Node(key, move(value));
|
||||||
if (!node)
|
if (!node)
|
||||||
return false;
|
return Error::from_errno(ENOMEM);
|
||||||
BaseTree::insert(node);
|
BaseTree::insert(node);
|
||||||
return true;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert(K key, V&& value)
|
void insert(K key, V&& value)
|
||||||
{
|
{
|
||||||
auto success = try_insert(key, move(value));
|
MUST(try_insert(key, move(value)));
|
||||||
VERIFY(success);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using Iterator = RedBlackTreeIterator<RedBlackTree, V>;
|
using Iterator = RedBlackTreeIterator<RedBlackTree, V>;
|
||||||
|
@ -267,8 +267,7 @@ ErrorOr<Region*> AddressSpace::add_region(NonnullOwnPtr<Region> region)
|
|||||||
{
|
{
|
||||||
auto* ptr = region.ptr();
|
auto* ptr = region.ptr();
|
||||||
SpinlockLocker lock(m_lock);
|
SpinlockLocker lock(m_lock);
|
||||||
if (!m_regions.try_insert(region->vaddr().get(), move(region)))
|
TRY(m_regions.try_insert(region->vaddr().get(), move(region)));
|
||||||
return ENOMEM;
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user