mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-24 09:52:31 +00:00
LibRegex: Use depth-first search in regex optimizer
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
use depth-first search in optimizer code bacause using breadth-first search generate a bug. Add test example in test lib.
This commit is contained in:
parent
2797f9f73e
commit
8a6f7b787e
Notes:
github-actions[bot]
2025-02-24 23:10:23 +00:00
Author: https://github.com/mikiubo
Commit: 8a6f7b787e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3681
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/gmta
2 changed files with 6 additions and 5 deletions
|
@ -6,11 +6,11 @@
|
|||
|
||||
#include <AK/Debug.h>
|
||||
#include <AK/Function.h>
|
||||
#include <AK/Queue.h>
|
||||
#include <AK/QuickSort.h>
|
||||
#include <AK/RedBlackTree.h>
|
||||
#include <AK/Stack.h>
|
||||
#include <AK/Trie.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibRegex/Regex.h>
|
||||
#include <LibRegex/RegexBytecodeStreamOptimizer.h>
|
||||
#include <LibUnicode/CharacterTypes.h>
|
||||
|
@ -1176,8 +1176,8 @@ void Optimizer::append_alternation(ByteCode& target, Span<ByteCode> alternatives
|
|||
patch_locations.append({ node_ip, target_ip });
|
||||
};
|
||||
|
||||
Queue<Tree*> nodes_to_visit;
|
||||
nodes_to_visit.enqueue(&trie);
|
||||
Vector<Tree*> nodes_to_visit;
|
||||
nodes_to_visit.append(&trie);
|
||||
|
||||
HashMap<size_t, NonnullOwnPtr<RedBlackTree<u64, u64>>> instruction_positions;
|
||||
if (has_any_backwards_jump)
|
||||
|
@ -1195,7 +1195,7 @@ void Optimizer::append_alternation(ByteCode& target, Span<ByteCode> alternatives
|
|||
// forkjump child2
|
||||
// ...
|
||||
while (!nodes_to_visit.is_empty()) {
|
||||
auto const* node = nodes_to_visit.dequeue();
|
||||
auto const* node = nodes_to_visit.take_last();
|
||||
for (auto& patch : patch_locations) {
|
||||
if (!patch.done && node_is(node, patch.source_ip)) {
|
||||
auto value = static_cast<ByteCodeValueType>(target.size() - patch.target_ip - 1);
|
||||
|
@ -1291,7 +1291,7 @@ void Optimizer::append_alternation(ByteCode& target, Span<ByteCode> alternatives
|
|||
target.append(static_cast<ByteCodeValueType>(OpCodeId::ForkJump));
|
||||
add_patch_point(child_node, target.size());
|
||||
target.append(static_cast<ByteCodeValueType>(0));
|
||||
nodes_to_visit.enqueue(child_node);
|
||||
nodes_to_visit.append(child_node);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue