Skip to content
Merged
Show file tree
Hide file tree
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 @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;

namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
Expand Down Expand Up @@ -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)
Expand All @@ -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<string> VoidElements = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, messed up the PR. source.get_FilePath shows on the profiler (as do some of the other property accessors) as part of thew UpdateState function call which appears very frequently. The FilePath does not change for a source document, so it seemed like a easy enough fix.

private int _position;
private int _current;
private SourceLocation _location;
Expand All @@ -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();
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down