Skip to content

Commit

Permalink
Remove _caseInsensitive field from RegexInterpreter (#67681)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed Apr 7, 2022
1 parent afb1c64 commit c61cb71
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ internal sealed class RegexInterpreter : RegexRunner
private RegexOpcode _operator;
private int _codepos;
private bool _rightToLeft;
private bool _caseInsensitive;

public RegexInterpreter(RegexInterpreterCode code, TextInfo? textInfo)
{
Expand Down Expand Up @@ -164,8 +163,7 @@ private void Backtrack()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetOperator(RegexOpcode op)
{
_operator = op & ~(RegexOpcode.RightToLeft | RegexOpcode.CaseInsensitive);
_caseInsensitive = (op & RegexOpcode.CaseInsensitive) != 0;
_operator = op & ~RegexOpcode.RightToLeft;
_rightToLeft = (op & RegexOpcode.RightToLeft) != 0;
}

Expand Down Expand Up @@ -265,7 +263,7 @@ private bool MatchString(string str, ReadOnlySpan<char> inputSpan)
return true;
}

private bool MatchRef(int index, int length, ReadOnlySpan<char> inputSpan)
private bool MatchRef(int index, int length, ReadOnlySpan<char> inputSpan, bool caseInsensitive)
{
int pos;
if (!_rightToLeft)
Expand All @@ -290,7 +288,7 @@ private bool MatchRef(int index, int length, ReadOnlySpan<char> inputSpan)
int cmpos = index + length;
int c = length;

if (!_caseInsensitive)
if (!caseInsensitive)
{
while (c-- != 0)
{
Expand Down Expand Up @@ -856,11 +854,12 @@ private bool TryMatchAtCurrentPosition(ReadOnlySpan<char> inputSpan)
continue;

case RegexOpcode.Backreference:
case RegexOpcode.Backreference | RegexOpcode.CaseInsensitive:
{
int capnum = Operand(0);
if (IsMatched(capnum))
{
if (!MatchRef(MatchIndex(capnum), MatchLength(capnum), inputSpan))
if (!MatchRef(MatchIndex(capnum), MatchLength(capnum), inputSpan, (_operator & RegexOpcode.CaseInsensitive) != 0))
{
break;
}
Expand Down Expand Up @@ -976,9 +975,9 @@ private bool TryMatchAtCurrentPosition(ReadOnlySpan<char> inputSpan)
char ch = (char)Operand(0);
int i;

if (!_rightToLeft && !_caseInsensitive)
if (!_rightToLeft)
{
// We're left-to-right and case-sensitive, so we can employ the vectorized IndexOf
// We're left-to-right, so we can employ the vectorized IndexOf
// to search for the character.
i = inputSpan.Slice(runtextpos, len).IndexOf(ch);
if (i == -1)
Expand Down

0 comments on commit c61cb71

Please sign in to comment.