mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
AK: Make HashMap::try_ensure work with a fallible construction callback
Co-authored-by: Timothy Flynn <trflynn89@pm.me>
This commit is contained in:
parent
2f4a83215c
commit
44de4d163b
Notes:
sideshowbarker
2024-07-18 02:47:59 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/44de4d163b Pull-request: https://github.com/SerenityOS/serenity/pull/17155
1 changed files with 7 additions and 2 deletions
|
@ -228,8 +228,13 @@ public:
|
|||
auto it = find(key);
|
||||
if (it != end())
|
||||
return it->value;
|
||||
auto result = TRY(try_set(key, initialization_callback()));
|
||||
VERIFY(result == HashSetResult::InsertedNewEntry);
|
||||
if constexpr (FallibleFunction<Callback>) {
|
||||
auto result = TRY(try_set(key, TRY(initialization_callback())));
|
||||
VERIFY(result == HashSetResult::InsertedNewEntry);
|
||||
} else {
|
||||
auto result = TRY(try_set(key, initialization_callback()));
|
||||
VERIFY(result == HashSetResult::InsertedNewEntry);
|
||||
}
|
||||
return find(key)->value;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue