Skip to content

Commit

Permalink
LibRegex: Don't immediately ignore TempInverse in optimizer
Browse files Browse the repository at this point in the history
fe46b2c added the reset-temp-inverse flag, but set it up so all
tempinverse ops were negated at the start of the next op; this commit
makes it so these flags actually persist for one op and not zero.

Fixes SerenityOS#2296.

(cherry picked from commit 00bc22c33268f0765adfcdf0ce00f23c35fff136)
  • Loading branch information
alimpfard authored and nico committed Nov 17, 2024
1 parent 9fc3e75 commit dbe6865
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Tests/LibRegex/Regex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,8 @@ TEST_CASE(optimizer_atomic_groups)
// (b+)(b+) produces an intermediate block with no matching ops, the optimiser should ignore that block when looking for following matches and correctly detect the overlap between (b+) and (b+).
// note that the second loop may be rewritten to a ForkReplace, but the first loop should not be rewritten.
Tuple { "(b+)(b+)"sv, "bbb"sv, true },
// Don't treat [\S] as [\s]; see ladybird#2296.
Tuple { "([^\\s]+?)\\(([\\s\\S]*)\\)"sv, "a(b)"sv, true },
};

for (auto& test : tests) {
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibRegex/RegexOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ static bool has_overlap(Vector<CompareTypeAndValuePair> const& lhs, Vector<Compa
break;
case CharacterCompareType::TemporaryInverse:
temporary_inverse = true;
reset_temporary_inverse = true;
reset_temporary_inverse = false;
break;
case CharacterCompareType::AnyChar:
// Special case: if not inverted, AnyChar is always in the range.
Expand Down Expand Up @@ -327,7 +327,7 @@ static bool has_overlap(Vector<CompareTypeAndValuePair> const& lhs, Vector<Compa
break;
case CharacterCompareType::TemporaryInverse:
temporary_inverse = true;
reset_temporary_inverse = true;
reset_temporary_inverse = false;
break;
case CharacterCompareType::AnyChar:
// Special case: if not inverted, AnyChar is always in the range.
Expand Down

0 comments on commit dbe6865

Please sign in to comment.