AK: Make HashMap::try_ensure work with a fallible construction callback

Co-authored-by: Timothy Flynn <trflynn89@pm.me>
This commit is contained in:
Nico Weber 2023-01-23 19:22:31 -05:00 committed by Linus Groh
parent 2f4a83215c
commit 44de4d163b
Notes: sideshowbarker 2024-07-18 02:47:59 +09:00

View file

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