Skip to content

Commit

Permalink
Micro-optimize IsMatch::CompareIgnoreCase
Browse files Browse the repository at this point in the history
  • Loading branch information
ladipro committed Feb 12, 2021
1 parent 6efb3d1 commit f3cf715
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Shared/FileMatcher.cs
Expand Up @@ -1672,13 +1672,15 @@ bool CompareIgnoreCase(char inputChar, char patternChar, int iIndex, int pIndex)
// We will mostly be comparing ASCII characters, check this first
if (inputChar < 128 && patternChar < 128)
{
if (inputChar >= 'A' && inputChar <= 'Z' && patternChar >= 'a' && patternChar <= 'z')
if (inputChar >= 'A' && inputChar <= 'Z')
{
return inputChar + 32 == patternChar;
// Evaluates to true if patternChar is equal to inputChar or to the lower-case counter-part.
return inputChar == (patternChar & ~0x20);
}
if (inputChar >= 'a' && inputChar <= 'z' && patternChar >= 'A' && patternChar <= 'Z')
if (inputChar >= 'a' && inputChar <= 'z')
{
return inputChar == patternChar + 32;
// Evaluates to true if patternChar is equal to inputChar or to the upper-case counter-part.
return inputChar == (patternChar | 0x20);
}
return inputChar == patternChar;
}
Expand Down

0 comments on commit f3cf715

Please sign in to comment.