diff options
author | therzok <marius.ungureanu@xamarin.com> | 2016-07-12 15:56:29 +0300 |
---|---|---|
committer | therzok <marius.ungureanu@xamarin.com> | 2016-07-12 16:14:30 +0300 |
commit | f22295dabe970a8a32205566c2474c6a562a0143 (patch) | |
tree | 4afde6fe76f1c0a5c2256bf57a18b5c5e0ca4667 /main | |
parent | f93588dd06a48f52c9c36da200277faf9d1e5a07 (diff) |
[General] Change some StringBuilder appends to not allocate strings.
This removes substring calls that allocate strings so chars are copied
from offsets into the stringbuilder.
Diffstat (limited to 'main')
13 files changed, 22 insertions, 21 deletions
diff --git a/main/src/addins/Deployment/MonoDevelop.Deployment/MonoDevelop.Deployment/DeployService.cs b/main/src/addins/Deployment/MonoDevelop.Deployment/MonoDevelop.Deployment/DeployService.cs index 51fbdf8329..b71d16825f 100644 --- a/main/src/addins/Deployment/MonoDevelop.Deployment/MonoDevelop.Deployment/DeployService.cs +++ b/main/src/addins/Deployment/MonoDevelop.Deployment/MonoDevelop.Deployment/DeployService.cs @@ -332,13 +332,13 @@ namespace MonoDevelop.Deployment string tag = text.Substring (pos + 1, ep - pos - 1); string dir = ctx.GetDirectory (tag); if (dir != null) { - sb.Append (text.Substring (lastPos, pos - lastPos)); + sb.Append (text, lastPos, pos - lastPos); sb.Append (dir); lastPos = ep + 1; } pos = text.IndexOf ('@', ep+1); } - sb.Append (text.Substring (lastPos, text.Length - lastPos)); + sb.Append (text, lastPos, text.Length - lastPos); string tmp = ctx.CreateTempFile (); TextFile.WriteFile (tmp, sb.ToString (), tf.SourceEncoding); return tmp; diff --git a/main/src/addins/MonoDevelop.Autotools/MakefileData.cs b/main/src/addins/MonoDevelop.Autotools/MakefileData.cs index a11cb8d733..01b78a04dc 100644 --- a/main/src/addins/MonoDevelop.Autotools/MakefileData.cs +++ b/main/src/addins/MonoDevelop.Autotools/MakefileData.cs @@ -1283,7 +1283,7 @@ namespace MonoDevelop.Autotools j ++; if (j >= len) { - sb.Append (filename.Substring (i)); + sb.Append (filename, i, filename.Length - i); break; } diff --git a/main/src/addins/MonoDevelop.DocFood/MonoDevelop.DocFood/DocGenerator.cs b/main/src/addins/MonoDevelop.DocFood/MonoDevelop.DocFood/DocGenerator.cs index 22dfccc500..00fa6eca7f 100644 --- a/main/src/addins/MonoDevelop.DocFood/MonoDevelop.DocFood/DocGenerator.cs +++ b/main/src/addins/MonoDevelop.DocFood/MonoDevelop.DocFood/DocGenerator.cs @@ -961,9 +961,9 @@ namespace MonoDevelop.DocFood continue; } if (i != j) - result.Append (name.Substring (j, i - j)); + result.Append (name, j, i - j); if (i + 1 < name.Length) { - result.Append (" "); + result.Append (' '); result.Append (char.ToLower (name [i])); } continue; diff --git a/main/src/addins/TextTemplating/TextTransform/Options.cs b/main/src/addins/TextTemplating/TextTransform/Options.cs index 663c804732..124ad72fd3 100644 --- a/main/src/addins/TextTemplating/TextTransform/Options.cs +++ b/main/src/addins/TextTemplating/TextTransform/Options.cs @@ -1021,7 +1021,7 @@ namespace Mono.Options sb.Append ("}"); } else { - sb.Append (description.Substring (start, i - start)); + sb.Append (description, start, i - start); start = -1; } break; diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/LogWidget.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/LogWidget.cs index 46f4d1d437..c43f927691 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/LogWidget.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/LogWidget.cs @@ -775,7 +775,7 @@ namespace MonoDevelop.VersionControl.Views int last = 0; while (i != -1) { sb.Append (GLib.Markup.EscapeText (txt.Substring (last, i - last))); - sb.Append ("<span color='" + Styles.LogView.SearchSnippetTextColor + "'>").Append (txt.Substring (i, filter.Length)).Append ("</span>"); + sb.Append ("<span color='" + Styles.LogView.SearchSnippetTextColor + "'>").Append (txt, i, filter.Length).Append ("</span>"); last = i + filter.Length; i = txt.IndexOf (filter, last, StringComparison.CurrentCultureIgnoreCase); } diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Assemblies/PcFileCache.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Assemblies/PcFileCache.cs index dc3afba937..167d48924e 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Assemblies/PcFileCache.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Assemblies/PcFileCache.cs @@ -538,7 +538,7 @@ namespace Mono.PkgConfig 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; @@ -564,7 +564,7 @@ namespace Mono.PkgConfig if (i < value.Length) 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/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Execution/LocalConsole.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Execution/LocalConsole.cs index 9731bde3f4..17b496bf80 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Execution/LocalConsole.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Execution/LocalConsole.cs @@ -226,18 +226,18 @@ namespace MonoDevelop.Core.Execution for (int i=idx; i < current.Length; i++) { if (current[i] == '\n') { idx = i + 1; - sb.Append (current.Substring (0, i)); + sb.Append (current, 0, i); return sb.ToString (); } if (current[i] == '\r') { idx = i + 1; - sb.Append (current.Substring (0, i)); + sb.Append (current, 0, i); if (LoadCurrent (true) && current [idx] == '\n') idx++; return sb.ToString (); } } - sb.Append (current.Substring (idx)); + sb.Append (current, idx, current.Length - idx); current = null; } return sb.ToString (); @@ -247,7 +247,7 @@ namespace MonoDevelop.Core.Execution { StringBuilder sb = new StringBuilder (); while (LoadCurrent (true)) { - sb.Append (current.Substring (idx)); + sb.Append (current, idx, current.Length - idx); current = null; } return sb.ToString (); diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/IMSBuildPropertySet.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/IMSBuildPropertySet.cs index c50d165ac6..eeb2a3177b 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/IMSBuildPropertySet.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/IMSBuildPropertySet.cs @@ -231,7 +231,7 @@ namespace MonoDevelop.Projects.MSBuild if (i != -1) { int fi = val.IndexOf ('\\'); if (fi != -1 && fi < i) i = fi; - sb.Append (val.Substring (0,i)); + sb.Append (val, 0,i)); } else i = 0; for (int n = i; n < val.Length; n++) { diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildProject.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildProject.cs index 187da6cd79..2a3b9c5463 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildProject.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildProject.cs @@ -984,7 +984,7 @@ namespace MonoDevelop.Projects.MSBuild if (i == -1) { res.Append (t); } else { - res.Append (t.Substring (i + 1)); + res.Append (t, i + 1, t.Length - i - 1); return res.ToString (); } } else diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Text/TextFormatter.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Text/TextFormatter.cs index aee449009a..cc1f54ac19 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Text/TextFormatter.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Text/TextFormatter.cs @@ -205,7 +205,7 @@ namespace MonoDevelop.Projects.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/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarController.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarController.cs index 1017e567cd..1921ff356c 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarController.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarController.cs @@ -908,7 +908,8 @@ namespace MonoDevelop.Components.MainToolbar int i = s.IndexOf ('_'); if (i == -1) return s; - var sb = new StringBuilder (s.Substring (0, i)); + var sb = new StringBuilder (i); + sb.Append (s, 0, i); for (; i < s.Length; i++) { if (s [i] == '_') { i++; diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/CodeTemplate.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/CodeTemplate.cs index 7dce1c43f7..bf3df1754c 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/CodeTemplate.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/CodeTemplate.cs @@ -230,7 +230,7 @@ namespace MonoDevelop.Ide.CodeTemplates result.TextLinks = new List<TextLink> (); foreach (System.Text.RegularExpressions.Match match in variableRegEx.Matches (code)) { string name = match.Groups [1].Value; - sb.Append (code.Substring (lastOffset, match.Index - lastOffset)); + sb.Append (code, lastOffset, match.Index - lastOffset); lastOffset = match.Index + match.Length; if (string.IsNullOrEmpty (name)) { // $$ is interpreted as $ sb.Append ("$"); @@ -283,7 +283,7 @@ namespace MonoDevelop.Ide.CodeTemplates AddDefaultValue (sb, link, name); } } - sb.Append (code.Substring (lastOffset, code.Length - lastOffset)); + sb.Append (code, lastOffset, code.Length - lastOffset); // format & indent template code var data = TextEditorFactory.CreateNewDocument (); diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/Ambience.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/Ambience.cs index 0e4ceda82a..1d4ec3dae0 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/Ambience.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/Ambience.cs @@ -247,7 +247,7 @@ namespace MonoDevelop.Ide.TypeSystem LoggingService.LogWarning ("Invalid cref:" + cref, e); } - if (cref.Substring (1, 1) == ":") + if (cref[1] == ':') return cref.Substring (2, cref.Length - 2); return cref; @@ -341,7 +341,7 @@ namespace MonoDevelop.Ide.TypeSystem public static string UnescapeText (string text) { - var sb = new StringBuilder (); + var sb = new StringBuilder (text.Length); for (int i = 0; i < text.Length; i++) { char ch = text[i]; if (ch == '&') { |