From cd460273427ac62e4ff3cd076c6898d678e02893 Mon Sep 17 00:00:00 2001 From: Marius Ungureanu Date: Tue, 12 Jul 2016 16:35:06 +0300 Subject: [PATCH] [Misc] Remove some extra string allocations. --- Mono.Addins.Gui/Mono.Addins.Gui/AddinTreeWidget.cs | 2 +- .../ProgressStatusMonitor.cs | 2 +- Mono.Addins.Setup/Mono.Addins.Setup/PcFileCache.cs | 4 ++-- Mono.Addins.Setup/Mono.Addins.Setup/TextFormatter.cs | 2 +- Mono.Addins/Mono.Addins.Description/AddinDescription.cs | 3 ++- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Mono.Addins.Gui/Mono.Addins.Gui/AddinTreeWidget.cs b/Mono.Addins.Gui/Mono.Addins.Gui/AddinTreeWidget.cs index 20324092..a91be436 100644 --- a/Mono.Addins.Gui/Mono.Addins.Gui/AddinTreeWidget.cs +++ b/Mono.Addins.Gui/Mono.Addins.Gui/AddinTreeWidget.cs @@ -352,7 +352,7 @@ string EscapeWithFilterMarker (string txt) int i = txt.IndexOf (filter, StringComparison.CurrentCultureIgnoreCase); while (i != -1) { sb.Append (GLib.Markup.EscapeText (txt.Substring (last, i - last))); - sb.Append ("").Append (txt.Substring (i, filter.Length)).Append (""); + sb.Append ("").Append (txt, i, filter.Length).Append (""); last = i + filter.Length; i = txt.IndexOf (filter, last, StringComparison.CurrentCultureIgnoreCase); } diff --git a/Mono.Addins.Setup/Mono.Addins.Setup.ProgressMonitoring/ProgressStatusMonitor.cs b/Mono.Addins.Setup/Mono.Addins.Setup.ProgressMonitoring/ProgressStatusMonitor.cs index b1bde237..952a80e1 100644 --- a/Mono.Addins.Setup/Mono.Addins.Setup.ProgressMonitoring/ProgressStatusMonitor.cs +++ b/Mono.Addins.Setup/Mono.Addins.Setup.ProgressMonitoring/ProgressStatusMonitor.cs @@ -102,7 +102,7 @@ void WriteLog (string text) pi = i + 1; i = text.IndexOf ('\n', pi); } - logBuffer.Append (text.Substring (pi)); + logBuffer.Append (text, pi, text.Length - pi); } public TextWriter Log { diff --git a/Mono.Addins.Setup/Mono.Addins.Setup/PcFileCache.cs b/Mono.Addins.Setup/Mono.Addins.Setup/PcFileCache.cs index cadccf3c..8c0d8979 100644 --- a/Mono.Addins.Setup/Mono.Addins.Setup/PcFileCache.cs +++ b/Mono.Addins.Setup/Mono.Addins.Setup/PcFileCache.cs @@ -546,7 +546,7 @@ string Evaluate (string value) StringBuilder sb = new StringBuilder (); int last = 0; while (i != -1 && i < value.Length) { - sb.Append (value.Substring (last, i - last)); + sb.Append (value, last, i - last); if (i == 0 || value [i - 1] != '$') { // Evaluate if var is not escaped i += 2; @@ -572,7 +572,7 @@ string Evaluate (string value) if (i < value.Length - 1) i = value.IndexOf ("${", i); } - sb.Append (value.Substring (last, value.Length - last)); + sb.Append (value, last, value.Length - last); return sb.ToString (); } } diff --git a/Mono.Addins.Setup/Mono.Addins.Setup/TextFormatter.cs b/Mono.Addins.Setup/Mono.Addins.Setup/TextFormatter.cs index 0aa37190..c1f37a1f 100644 --- a/Mono.Addins.Setup/Mono.Addins.Setup/TextFormatter.cs +++ b/Mono.Addins.Setup/Mono.Addins.Setup/TextFormatter.cs @@ -201,7 +201,7 @@ public void Append (string text) } if (n != sn) - currentWord.Append (text.Substring (sn, n - sn)); + currentWord.Append (text, sn, n - sn); if (foundSpace) { AppendCurrentWord (text[n]); n++; diff --git a/Mono.Addins/Mono.Addins.Description/AddinDescription.cs b/Mono.Addins/Mono.Addins.Description/AddinDescription.cs index 6b3059b2..724204f8 100644 --- a/Mono.Addins/Mono.Addins.Description/AddinDescription.cs +++ b/Mono.Addins/Mono.Addins.Description/AddinDescription.cs @@ -1009,7 +1009,8 @@ internal string ParseString (string input) if (i == -1) return input; - StringBuilder result = new StringBuilder (input.Substring (0, i), input.Length); + StringBuilder result = new StringBuilder (input.Length); + result.Append (input, 0, i); while (i < input.Length) { if (input [i] == '$') {