diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Legacy/ParserHelpers.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Legacy/ParserHelpers.cs index 17f015e7ea4e..58be8a9d04ee 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Legacy/ParserHelpers.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Legacy/ParserHelpers.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; +using System.Runtime.CompilerServices; namespace Microsoft.AspNetCore.Razor.Language.Legacy { @@ -55,28 +56,9 @@ public static bool IsIdentifierStart(char value) public static bool IsIdentifierPart(char value) { - return IsLetter(value) - || IsDecimalDigit(value) - || IsConnecting(value) - || IsCombining(value) - || IsFormatting(value); - } - - public static bool IsFormatting(char value) - { - return CharUnicodeInfo.GetUnicodeCategory(value) == UnicodeCategory.Format; - } - - public static bool IsCombining(char value) - { - var cat = CharUnicodeInfo.GetUnicodeCategory(value); - - return cat == UnicodeCategory.SpacingCombiningMark || cat == UnicodeCategory.NonSpacingMark; - } - - public static bool IsConnecting(char value) - { - return CharUnicodeInfo.GetUnicodeCategory(value) == UnicodeCategory.ConnectorPunctuation; + return IsLetter(value) || + IsDecimalDigit(value) || + (CharUnicodeInfo.GetUnicodeCategory(value) is UnicodeCategory.Format or UnicodeCategory.SpacingCombiningMark or UnicodeCategory.NonSpacingMark or UnicodeCategory.ConnectorPunctuation); } public static bool IsWhitespace(char value) @@ -85,25 +67,14 @@ public static bool IsWhitespace(char value) value == '\f' || value == '\t' || value == '\u000B' || // Vertical Tab - CharUnicodeInfo.GetUnicodeCategory(value) == UnicodeCategory.SpaceSeparator; + char.IsSeparator(value);; } - public static bool IsLetter(char value) - { - var cat = CharUnicodeInfo.GetUnicodeCategory(value); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool IsLetter(char value) => char.IsLetter(value); - return cat == UnicodeCategory.UppercaseLetter - || cat == UnicodeCategory.LowercaseLetter - || cat == UnicodeCategory.TitlecaseLetter - || cat == UnicodeCategory.ModifierLetter - || cat == UnicodeCategory.OtherLetter - || cat == UnicodeCategory.LetterNumber; - } - - public static bool IsDecimalDigit(char value) - { - return CharUnicodeInfo.GetUnicodeCategory(value) == UnicodeCategory.DecimalDigitNumber; - } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool IsDecimalDigit(char value) => char.IsDigit(value); // From http://dev.w3.org/html5/spec/Overview.html#elements-0 public static readonly HashSet VoidElements = new HashSet(StringComparer.OrdinalIgnoreCase) diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Legacy/SeekableTextReader.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Legacy/SeekableTextReader.cs index 599002e25679..2722e1155543 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Legacy/SeekableTextReader.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Legacy/SeekableTextReader.cs @@ -8,9 +8,10 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy { - internal class SeekableTextReader : TextReader, ITextDocument + internal sealed class SeekableTextReader : TextReader, ITextDocument { private readonly RazorSourceDocument _sourceDocument; + private readonly string _filePath; private int _position; private int _current; private SourceLocation _location; @@ -20,12 +21,8 @@ internal class SeekableTextReader : TextReader, ITextDocument public SeekableTextReader(RazorSourceDocument source) { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } - _sourceDocument = source; + _filePath = source.FilePath; _cachedLineInfo = (new TextSpan(0, _sourceDocument.Lines.GetLineLength(0)), 0); UpdateState(); } @@ -61,7 +58,7 @@ private void UpdateState() { if (_cachedLineInfo.Span.Contains(_position)) { - _location = new SourceLocation(_sourceDocument.FilePath, _position, _cachedLineInfo.LineIndex, _position - _cachedLineInfo.Span.Start); + _location = new SourceLocation(_filePath, _position, _cachedLineInfo.LineIndex, _position - _cachedLineInfo.Span.Start); _current = _sourceDocument[_location.AbsoluteIndex]; return; @@ -79,7 +76,7 @@ private void UpdateState() if (nextLineSpan.Contains(_position)) { _cachedLineInfo = (nextLineSpan, nextLineIndex); - _location = new SourceLocation(_sourceDocument.FilePath, _position, nextLineIndex, _position - nextLineSpan.Start); + _location = new SourceLocation(_filePath, _position, nextLineIndex, _position - nextLineSpan.Start); _current = _sourceDocument[_location.AbsoluteIndex]; return; @@ -95,7 +92,7 @@ private void UpdateState() if (prevLineSpan.Contains(_position)) { _cachedLineInfo = (prevLineSpan, prevLineIndex); - _location = new SourceLocation(_sourceDocument.FilePath, _position, prevLineIndex, _position - prevLineSpan.Start); + _location = new SourceLocation(_filePath, _position, prevLineIndex, _position - prevLineSpan.Start); _current = _sourceDocument[_location.AbsoluteIndex]; return; @@ -123,7 +120,7 @@ private void UpdateState() } var lineNumber = _sourceDocument.Lines.Count - 1; - _location = new SourceLocation(_sourceDocument.FilePath, Length, lineNumber, _sourceDocument.Lines.GetLineLength(lineNumber)); + _location = new SourceLocation(_filePath, Length, lineNumber, _sourceDocument.Lines.GetLineLength(lineNumber)); _current = -1; }