Skip to content

Commit 7703d81

Browse files
authored
Update HtmlDocument.cs
Avoid string concat and substring operations to optimize memory usage.
1 parent 346c5e2 commit 7703d81

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/HtmlAgilityPack.Shared/HtmlDocument.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,8 +1741,16 @@ private void Parse()
17411741
// check buffer end
17421742
if ((_currentnode._namelength + 3) <= (Text.Length - (_index - 1)))
17431743
{
1744-
if (string.Compare(Text.Substring(_index - 1, _currentnode._namelength + 2),
1745-
"</" + _currentnode.Name, StringComparison.OrdinalIgnoreCase) == 0)
1744+
var tagStartMatching = Text[_index - 1] == '<' && Text[_index] == '/';
1745+
var tagMatching = string.Compare(
1746+
Text,
1747+
_index + 1,
1748+
_currentnode.Name,
1749+
0,
1750+
_currentnode._namelength,
1751+
StringComparison.OrdinalIgnoreCase)
1752+
== 0;
1753+
if (tagStartMatching && tagMatching)
17461754
{
17471755
int c = Text[_index - 1 + 2 + _currentnode.Name.Length];
17481756
if ((c == '>') || (IsWhiteSpace(c)))

0 commit comments

Comments
 (0)