Skip to content

Commit

Permalink
Don't allocate AttributesCollection in HtmlNode.GetId unless needed
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed Jun 29, 2024
1 parent 8efd5da commit d5c0caf
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/HtmlAgilityPack.Shared/HtmlNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,7 @@ public HtmlNode FirstChild
/// </summary>
public bool HasAttributes
{
get
{
if (_attributes == null)
{
return false;
}

if (_attributes.Count <= 0)
{
return false;
}

return true;
}
get { return _attributes != null && _attributes.Count > 0; }
}

/// <summary>
Expand Down Expand Up @@ -2324,7 +2311,7 @@ internal void CloseNode(HtmlNode endnode, int level = 0)

internal string GetId()
{
HtmlAttribute att = Attributes["id"];
HtmlAttribute att = HasAttributes ? Attributes["id"] : null;
return att == null ? string.Empty : att.Value;
}

Expand Down

0 comments on commit d5c0caf

Please sign in to comment.