Skip to content

Commit

Permalink
Merge pull request #541 from 3bdNKocY/3bdNKocY-patch-1
Browse files Browse the repository at this point in the history
Avoid creating new strings when parsing PcData
  • Loading branch information
JonathanMagnan authored Mar 27, 2024
2 parents 2806ec5 + 7703d81 commit d1574ef
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/HtmlAgilityPack.Shared/HtmlDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1741,8 +1741,16 @@ private void Parse()
// check buffer end
if ((_currentnode._namelength + 3) <= (Text.Length - (_index - 1)))
{
if (string.Compare(Text.Substring(_index - 1, _currentnode._namelength + 2),
"</" + _currentnode.Name, StringComparison.OrdinalIgnoreCase) == 0)
var tagStartMatching = Text[_index - 1] == '<' && Text[_index] == '/';
var tagMatching = string.Compare(
Text,
_index + 1,
_currentnode.Name,
0,
_currentnode._namelength,
StringComparison.OrdinalIgnoreCase)
== 0;
if (tagStartMatching && tagMatching)
{
int c = Text[_index - 1 + 2 + _currentnode.Name.Length];
if ((c == '>') || (IsWhiteSpace(c)))
Expand Down

0 comments on commit d1574ef

Please sign in to comment.