Skip to content

Commit 3b043e4

Browse files
committed
кэшировать размер кода
1 parent 4f5b647 commit 3b043e4

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/OneScript.Language/LexicalAnalysis/SourceCodeIterator.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class SourceCodeIterator : ISourceCodeIndexer
1818
private int _lineCounter;
1919
private int _index;
2020
private int _startPosition;
21+
private int _codeLength;
2122

2223
private List<int> _lineBounds;
2324
private bool _onNewLine;
@@ -44,6 +45,7 @@ internal SourceCodeIterator()
4445
private void InitOnString(string code)
4546
{
4647
_code = code;
48+
_codeLength = code.Length;
4749
int cap = code.Length < 512 ? 32 : 512;
4850
_lineBounds = new List<int>(cap);
4951
_index = OUT_OF_TEXT;
@@ -70,7 +72,7 @@ private void InitOnString(string code)
7072
public int CurrentColumn
7173
{
7274
get
73-
{
75+
{
7476
if (_startPosition == OUT_OF_TEXT)
7577
{
7678
return OUT_OF_TEXT;
@@ -87,13 +89,13 @@ public int CurrentColumn
8789
public bool MoveNext()
8890
{
8991
_index++;
90-
if (_index < _code.Length)
92+
if (_index < _codeLength)
9193
{
9294
_currentSymbol = _code[_index];
9395
if (_currentSymbol == '\n')
9496
{
9597
_lineCounter++;
96-
if (_index < _code.Length)
98+
if (_index < _codeLength)
9799
_lineBounds.Add(_index + 1);
98100
}
99101

@@ -109,7 +111,7 @@ public bool MoveNext()
109111
public char PeekNext()
110112
{
111113
char result = '\0';
112-
if (_index + 1 < _code.Length)
114+
if (_index + 1 < _codeLength)
113115
{
114116
result = _code[_index + 1];
115117
}
@@ -155,7 +157,7 @@ public bool SkipSpaces()
155157
}
156158
}
157159

158-
if (_index >= _code.Length)
160+
if (_index >= _codeLength)
159161
{
160162
return false;
161163
}
@@ -200,7 +202,7 @@ public ReadOnlyMemory<char> GetContentSpan()
200202
{
201203
int len;
202204

203-
if (_startPosition == _index && _startPosition < _code.Length)
205+
if (_startPosition == _index && _startPosition < _codeLength)
204206
{
205207
len = 1;
206208
}

0 commit comments

Comments
 (0)