From e36940ebdfc3f3f7e986b8342bea2075741bb9ee Mon Sep 17 00:00:00 2001 From: Tora-Bora Date: Thu, 26 Sep 2019 15:26:02 +1000 Subject: [PATCH] string concatenation to StringBuilder.Append 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. --- src/HtmlAgilityPack.Shared/HtmlNode.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/HtmlAgilityPack.Shared/HtmlNode.cs b/src/HtmlAgilityPack.Shared/HtmlNode.cs index 92c41c9..9df390b 100644 --- a/src/HtmlAgilityPack.Shared/HtmlNode.cs +++ b/src/HtmlAgilityPack.Shared/HtmlNode.cs @@ -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; @@ -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(); } /// Gets direct inner text. @@ -2487,4 +2487,4 @@ private bool IsEmpty(IEnumerable en) #endregion } -} \ No newline at end of file +}