From 3594ac60c790cc5d3b39ea0d956cc8ee8985d0c8 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Mon, 24 Aug 2020 05:10:54 +0100 Subject: [PATCH] Add StringUtil.Format overload to avoid unnecessary allocations (#13408) * Rename parameters to correspond to string.Format * Add addtional overload to avoid allocations at call sites --- .../utils/StringUtil.cs | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/System.Management.Automation/utils/StringUtil.cs b/src/System.Management.Automation/utils/StringUtil.cs index 9a95407df7..0b74385d33 100644 --- a/src/System.Management.Automation/utils/StringUtil.cs +++ b/src/System.Management.Automation/utils/StringUtil.cs @@ -11,26 +11,17 @@ namespace System.Management.Automation.Internal internal static class StringUtil { - internal static - string - Format(string formatSpec, object o) - { - return string.Format(System.Globalization.CultureInfo.CurrentCulture, formatSpec, o); - } + internal static string Format(string format, object arg0) + => string.Format(Globalization.CultureInfo.CurrentCulture, format, arg0); - internal static - string - Format(string formatSpec, object o1, object o2) - { - return string.Format(System.Globalization.CultureInfo.CurrentCulture, formatSpec, o1, o2); - } + internal static string Format(string format, object arg0, object arg1) + => string.Format(Globalization.CultureInfo.CurrentCulture, format, arg0, arg1); - internal static - string - Format(string formatSpec, params object[] o) - { - return string.Format(System.Globalization.CultureInfo.CurrentCulture, formatSpec, o); - } + internal static string Format(string format, object arg0, object arg1, object arg2) + => string.Format(Globalization.CultureInfo.CurrentCulture, format, arg0, arg1, arg2); + + internal static string Format(string format, params object[] args) + => string.Format(Globalization.CultureInfo.CurrentCulture, format, args); internal static string