Skip to content

Commit

Permalink
Add EmitCallCharInClass optimization for singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed Jan 9, 2020
1 parent 26a848f commit 3cd3b37
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3050,11 +3050,20 @@ private void EmitCallCharInClass(string charClass, bool caseInsensitive, LocalBu
charClass[RegexCharClass.CategoryLengthIndex] == 0 && // must not have any categories
charClass[RegexCharClass.SetStartIndex] < charClass[RegexCharClass.SetStartIndex + 1]) // valid range
{
// (uint)ch - charClass[3] < charClass[4] - charClass[3]
Ldc(charClass[RegexCharClass.SetStartIndex]);
Sub();
Ldc(charClass[RegexCharClass.SetStartIndex + 1] - charClass[RegexCharClass.SetStartIndex]);
CltUn();
if (RegexCharClass.IsSingleton(charClass) || RegexCharClass.IsSingletonInverse(charClass))
{
// ch == charClass[3]
Ldc(charClass[3]);
Ceq();
}
else
{
// (uint)ch - charClass[3] < charClass[4] - charClass[3]
Ldc(charClass[RegexCharClass.SetStartIndex]);
Sub();
Ldc(charClass[RegexCharClass.SetStartIndex + 1] - charClass[RegexCharClass.SetStartIndex]);
CltUn();
}

// Negate the answer if the negation flag was set
if (RegexCharClass.IsNegated(charClass))
Expand Down

0 comments on commit 3cd3b37

Please sign in to comment.