diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2022-02-14 12:03:33 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-14 11:30:50 +0100 |
commit | 3b0943d24cf03f27a69debb3472d1f5e8a6e029b (patch) | |
tree | 48c33d985650399ca1b88119d876a3f4a68f82c3 /Userland/Libraries/LibRegex | |
parent | 76e99fa6c8213ef8788ecb05dd45fbd80c6a9483 (diff) | |
download | serenity-3b0943d24cf03f27a69debb3472d1f5e8a6e029b.zip |
LibRegex: Correct the alternative matching order when one is empty
Previously we were compiling `/a|/` into what effectively would be
`/|a`, which is clearly incorrect.
Diffstat (limited to 'Userland/Libraries/LibRegex')
-rw-r--r-- | Userland/Libraries/LibRegex/RegexOptimizer.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/Userland/Libraries/LibRegex/RegexOptimizer.cpp b/Userland/Libraries/LibRegex/RegexOptimizer.cpp index 969f37143c..f0d2912965 100644 --- a/Userland/Libraries/LibRegex/RegexOptimizer.cpp +++ b/Userland/Libraries/LibRegex/RegexOptimizer.cpp @@ -450,17 +450,17 @@ void Optimizer::append_alternation(ByteCode& target, ByteCode&& left, ByteCode&& if (left_is_empty && right_is_empty) return; - // ForkJump right (+ left.size() + 2 + right.size()) - // (left) - // Jump end (+ right.size()) + // ForkJump left (+ 2 + right.size()) // (right) + // Jump end (+ left.size()) + // (left) // LABEL end target.append(static_cast<ByteCodeValueType>(OpCodeId::ForkJump)); - target.append(left.size() + 2 + right.size()); - target.extend(move(left)); - target.append(static_cast<ByteCodeValueType>(OpCodeId::Jump)); - target.append(right.size()); + target.append(2 + right.size()); target.extend(move(right)); + target.append(static_cast<ByteCodeValueType>(OpCodeId::Jump)); + target.append(left.size()); + target.extend(move(left)); return; } |