Skip to content

Commit ee2baf3

Browse files
committed
Don't keep computing length
1 parent 1a264e2 commit ee2baf3

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Html2Text/Lexing/Lexer.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,10 @@ private ReadOnlyMemory<char> GetTagName()
161161

162162
private bool TryCompleteTag(ReadOnlyMemory<char> tagName)
163163
{
164+
var htmlLength = _html.Length;
165+
164166
// tag names must be followed by whitespace, '/>', '?>, or '>' to be valid
165-
char afterName = _cursor < _html.Length ? _html.Span[_cursor] : char.MinValue;
167+
char afterName = _cursor < htmlLength ? _html.Span[_cursor] : char.MinValue;
166168
if (!(char.IsWhiteSpace(afterName)
167169
|| afterName == '>'
168170
|| afterName == '/'
@@ -173,7 +175,7 @@ private bool TryCompleteTag(ReadOnlyMemory<char> tagName)
173175

174176
bool containsBadChars = false;
175177

176-
while (_cursor < _html.Length && _html.Span[_cursor] != '>')
178+
while (_cursor < htmlLength && _html.Span[_cursor] != '>')
177179
{
178180
// check that we do not have '<' character present in the tag
179181
if (_html.Span[_cursor] == '<')
@@ -184,7 +186,7 @@ private bool TryCompleteTag(ReadOnlyMemory<char> tagName)
184186
_cursor++;
185187
}
186188

187-
if (_cursor == _html.Length)
189+
if (_cursor == htmlLength)
188190
{
189191
// reached the end of the document without finding '>'
190192
return false;

0 commit comments

Comments
 (0)