88
99namespace Microsoft . AspNetCore . Razor . Language . Legacy
1010{
11- internal class SeekableTextReader : TextReader , ITextDocument
11+ internal sealed class SeekableTextReader : TextReader , ITextDocument
1212 {
1313 private readonly RazorSourceDocument _sourceDocument ;
14+ private readonly string _filePath ;
1415 private int _position ;
1516 private int _current ;
1617 private SourceLocation _location ;
@@ -20,12 +21,8 @@ internal class SeekableTextReader : TextReader, ITextDocument
2021
2122 public SeekableTextReader ( RazorSourceDocument source )
2223 {
23- if ( source == null )
24- {
25- throw new ArgumentNullException ( nameof ( source ) ) ;
26- }
27-
2824 _sourceDocument = source ;
25+ _filePath = source . FilePath ;
2926 _cachedLineInfo = ( new TextSpan ( 0 , _sourceDocument . Lines . GetLineLength ( 0 ) ) , 0 ) ;
3027 UpdateState ( ) ;
3128 }
@@ -61,7 +58,7 @@ private void UpdateState()
6158 {
6259 if ( _cachedLineInfo . Span . Contains ( _position ) )
6360 {
64- _location = new SourceLocation ( _sourceDocument . FilePath , _position , _cachedLineInfo . LineIndex , _position - _cachedLineInfo . Span . Start ) ;
61+ _location = new SourceLocation ( _filePath , _position , _cachedLineInfo . LineIndex , _position - _cachedLineInfo . Span . Start ) ;
6562 _current = _sourceDocument [ _location . AbsoluteIndex ] ;
6663
6764 return ;
@@ -79,7 +76,7 @@ private void UpdateState()
7976 if ( nextLineSpan . Contains ( _position ) )
8077 {
8178 _cachedLineInfo = ( nextLineSpan , nextLineIndex ) ;
82- _location = new SourceLocation ( _sourceDocument . FilePath , _position , nextLineIndex , _position - nextLineSpan . Start ) ;
79+ _location = new SourceLocation ( _filePath , _position , nextLineIndex , _position - nextLineSpan . Start ) ;
8380 _current = _sourceDocument [ _location . AbsoluteIndex ] ;
8481
8582 return ;
@@ -95,7 +92,7 @@ private void UpdateState()
9592 if ( prevLineSpan . Contains ( _position ) )
9693 {
9794 _cachedLineInfo = ( prevLineSpan , prevLineIndex ) ;
98- _location = new SourceLocation ( _sourceDocument . FilePath , _position , prevLineIndex , _position - prevLineSpan . Start ) ;
95+ _location = new SourceLocation ( _filePath , _position , prevLineIndex , _position - prevLineSpan . Start ) ;
9996 _current = _sourceDocument [ _location . AbsoluteIndex ] ;
10097
10198 return ;
@@ -123,7 +120,7 @@ private void UpdateState()
123120 }
124121
125122 var lineNumber = _sourceDocument . Lines . Count - 1 ;
126- _location = new SourceLocation ( _sourceDocument . FilePath , Length , lineNumber , _sourceDocument . Lines . GetLineLength ( lineNumber ) ) ;
123+ _location = new SourceLocation ( _filePath , Length , lineNumber , _sourceDocument . Lines . GetLineLength ( lineNumber ) ) ;
127124
128125 _current = - 1 ;
129126 }
0 commit comments