Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ private char Forwardcharnext(ReadOnlySpan<char> inputSpan)
private bool MatchString(string str, ReadOnlySpan<char> inputSpan)
{
int c = str.Length;
int pos;

if (!_rightToLeft)
{
Expand All @@ -219,7 +218,13 @@ private bool MatchString(string str, ReadOnlySpan<char> inputSpan)
return false;
}

pos = runtextpos + c;
if (!inputSpan.Slice(runtextpos, c).SequenceEqual(str.AsSpan()))
{
return false;
}

runtextpos += c;
return true;
}
else
{
Expand All @@ -228,25 +233,18 @@ private bool MatchString(string str, ReadOnlySpan<char> inputSpan)
return false;
}

pos = runtextpos;
}

while (c != 0)
{
if (str[--c] != inputSpan[--pos])
int pos = runtextpos;
while (c != 0)
{
return false;
if (str[--c] != inputSpan[--pos])
{
return false;
}
}
Comment on lines +237 to 243
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can/should this also be a SequenceEqual or EndsWith or equivalent?

}

if (!_rightToLeft)
{
pos += str.Length;
runtextpos = pos;
return true;
}

runtextpos = pos;

return true;
}

private bool MatchRef(int index, int length, ReadOnlySpan<char> inputSpan, bool caseInsensitive)
Expand Down Expand Up @@ -896,12 +894,23 @@ private bool TryMatchAtCurrentPosition(ReadOnlySpan<char> inputSpan)
}

char ch = (char)Operand(0);
while (c-- > 0)
if (!_rightToLeft)
{
if (Forwardcharnext(inputSpan) != ch)
if (inputSpan.Slice(runtextpos, c).ContainsAnyExcept(ch))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this one actually beneficial? It's pretty rare to have long runs of a single specific character.

{
goto BreakBackward;
}
runtextpos += c;
}
else
{
while (c-- > 0)
{
if (Forwardcharnext(inputSpan) != ch)
{
goto BreakBackward;
}
}
}
}
advance = 2;
Expand All @@ -916,12 +925,23 @@ private bool TryMatchAtCurrentPosition(ReadOnlySpan<char> inputSpan)
}

char ch = (char)Operand(0);
while (c-- > 0)
if (!_rightToLeft)
{
if (Forwardcharnext(inputSpan) == ch)
if (inputSpan.Slice(runtextpos, c).Contains(ch))
{
goto BreakBackward;
}
runtextpos += c;
}
else
{
while (c-- > 0)
{
if (Forwardcharnext(inputSpan) == ch)
{
goto BreakBackward;
}
}
}
}
advance = 2;
Expand Down Expand Up @@ -957,12 +977,31 @@ private bool TryMatchAtCurrentPosition(ReadOnlySpan<char> inputSpan)
char ch = (char)Operand(0);
int i;

for (i = len; i > 0; i--)
if (!_rightToLeft)
{
if (Forwardcharnext(inputSpan) != ch)
// We're left-to-right, so we can employ the vectorized IndexOfAnyExcept
// to search for any character that isn't the target.
i = inputSpan.Slice(runtextpos, len).IndexOfAnyExcept(ch);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question.

If these onerep/loop/loopatomic actually improve performance on real regexes rather than microbenchmarks targeting these cases, great. Otherwise, though, I'd rather avoid adding more specialized code paths for things that only help with fake scenarios.

if (i == -1)
{
Backwardnext();
break;
runtextpos += len;
i = 0;
}
else
{
runtextpos += i;
i = len - i;
}
}
else
{
for (i = len; i > 0; i--)
{
if (Forwardcharnext(inputSpan) != ch)
{
Backwardnext();
break;
}
}
}

Expand Down
Loading