Skip to content

Commit

Permalink
string concatenation to StringBuilder.Append
Browse files Browse the repository at this point in the history
I got an issue with getting InnerText for large html, it just got stuck with huge memory consumption. I found that changing string to StringBuilder in this method solves the problem.
  • Loading branch information
Tora-Bora committed Sep 26, 2019
1 parent 250a2b8 commit e36940e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/HtmlAgilityPack.Shared/HtmlNode.cs
Expand Up @@ -3,7 +3,7 @@
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
// More projects: http://www.zzzprojects.com/
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.

using System;
using System.Collections;
Expand Down Expand Up @@ -423,10 +423,10 @@ internal virtual string InternalInnerText(bool isDisplayScriptingText)
if (!HasChildNodes || ( _isHideInnerText && !isDisplayScriptingText))
return string.Empty;

string s = null;
var s = new StringBuilder;
foreach (HtmlNode node in ChildNodes)
s += node.InternalInnerText(isDisplayScriptingText);
return s;
s.Append(node.InternalInnerText(isDisplayScriptingText));
return s.ToString();
}

/// <summary>Gets direct inner text.</summary>
Expand Down Expand Up @@ -2487,4 +2487,4 @@ private bool IsEmpty(IEnumerable en)

#endregion
}
}
}

0 comments on commit e36940e

Please sign in to comment.