Improve HtmlTokenizer.AtToken performance. (dotnet/aspnetcore-tooling#1880)

Our razor typing test measured 153 CPU ms in this method. Optimized by fewer calls to CurrentCharacter, not checking '<' twice, and uswing a switch stmt.\n\nCommit migrated from c601c2f11e
This commit is contained in:
Todd Grunke 2020-05-11 10:26:56 -07:00 committed by GitHub
parent f701a188c2
commit d1e7d8e466
1 changed files with 20 additions and 14 deletions

View File

@ -253,21 +253,27 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return EndToken(SyntaxKind.NewLine);
}
private bool AtToken()
private bool AtToken()
{
return CurrentCharacter == '<' ||
CurrentCharacter == '<' ||
CurrentCharacter == '!' ||
CurrentCharacter == '/' ||
CurrentCharacter == '?' ||
CurrentCharacter == '[' ||
CurrentCharacter == '>' ||
CurrentCharacter == ']' ||
CurrentCharacter == '=' ||
CurrentCharacter == '"' ||
CurrentCharacter == '\'' ||
CurrentCharacter == '@' ||
(CurrentCharacter == '-' && Peek() == '-');
switch (CurrentCharacter)
{
case '<':
case '!':
case '/':
case '?':
case '[':
case '>':
case ']':
case '=':
case '"':
case '\'':
case '@':
return true;
case '-':
return Peek() == '-';
}
return false;
}
private StateResult Transition(HtmlTokenizerState state)