1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:07:45 +00:00

AK+Kernel: OOM-harden most parts of Trie

The only part of Unveil that can't handle OOM gracefully is the
String::formatted() use in the node metadata.
This commit is contained in:
Ali Mohammad Pur 2022-02-14 16:49:53 +03:30 committed by Idan Horowitz
parent 80e6198563
commit a1cb2c371a
9 changed files with 145 additions and 99 deletions

View file

@ -16,12 +16,13 @@ TEST_CASE(normal_behavior)
constexpr size_t total_chars = 18; // root (1), 'test' (4), 'example' (7), 'foo' (3), 'foobar' (3, "foo" already stored).
for (auto& view : data) {
auto it = view.begin();
dictionary.insert(it, view.end(), view, [](auto& parent, auto& it) -> Optional<String> { return String::formatted("{}{}", parent.metadata_value(), *it); });
MUST(dictionary.insert(it, view.end(), view, [](auto& parent, auto& it) -> Optional<String> { return String::formatted("{}{}", parent.metadata_value(), *it); }));
}
size_t i = 0;
for ([[maybe_unused]] auto& node : dictionary)
MUST(dictionary.for_each_node_in_tree_order([&](auto&) {
++i;
}));
EXPECT_EQ(i, total_chars);
for (auto& view : data) {
@ -49,18 +50,18 @@ TEST_CASE(iterate)
for (size_t i = 0; i < input.size(); ++i)
input[i] = i;
bunch_of_numbers.insert(input.begin(), input.end());
MUST(bunch_of_numbers.insert(input.begin(), input.end()));
// Iteration order is preorder (order between adjacent nodes is not defined, but parents come before children)
// in this case, the tree is linear.
size_t i = 0;
bool is_root = true;
for (auto& node : bunch_of_numbers) {
MUST(bunch_of_numbers.for_each_node_in_tree_order([&](auto& node) {
if (is_root) {
is_root = false;
continue;
return;
}
EXPECT_EQ(input[i], node.value());
++i;
}
}));
}