AK+LibRegex: Only set node metadata on Trie::ensure_child if missing

a290034a81 passed an empty vector to this,
which caused nodes that appeared multiple times to reset the trie
metadata...which broke the optimisation.

This patchset makes the function take a 'provide missing metadata'
function instead, and only invokes it when the node is missing rather
than unconditionally setting the metadata on all nodes.
This commit is contained in:
Ali Mohammad Pur 2025-11-20 23:47:21 +01:00 committed by Ali Mohammad Pur
parent 2c5beeabe3
commit d5d37abfa5
Notes: github-actions[bot] 2025-11-21 01:47:30 +00:00
2 changed files with 17 additions and 11 deletions

View file

@ -1467,7 +1467,7 @@ void Optimizer::append_alternation(ByteCode& target, Span<ByteCode> alternatives
node_key_bytes.append(edge.jump_insn);
}
active_node = static_cast<decltype(active_node)>(MUST(active_node->ensure_child(DisjointSpans<ByteCodeValueType const> { move(node_key_bytes) }, Vector<NodeMetadataEntry> {})));
active_node = static_cast<decltype(active_node)>(MUST(active_node->ensure_child(DisjointSpans<ByteCodeValueType const> { move(node_key_bytes) }, [] -> Vector<NodeMetadataEntry> { return {}; })));
auto next_compare = [&alternative, &state](StaticallyInterpretedCompares& compares) {
TemporaryChange state_change { state.instruction_position, state.instruction_position };