diff --git a/Src/Newtonsoft.Json/Utilities/StringUtils.cs b/Src/Newtonsoft.Json/Utilities/StringUtils.cs index 22e79400..659b3657 100644 --- a/Src/Newtonsoft.Json/Utilities/StringUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/StringUtils.cs @@ -60,8 +60,15 @@ namespace Newtonsoft.Json.Utilities return format.FormatWith(provider, new[] { arg0, arg1, arg2 }); } - public static string FormatWith(this string format, IFormatProvider provider, params object[] args) + public static string FormatWith(this string format, IFormatProvider provider, object arg0, object arg1, object arg2, object arg3) { + return format.FormatWith(provider, new[] { arg0, arg1, arg2, arg3 }); + } + + private static string FormatWith(this string format, IFormatProvider provider, params object[] args) + { + // leave this a private to force code to use an explicit overload + // avoids stack memory being reserved for the object array ValidationUtils.ArgumentNotNull(format, "format"); return string.Format(provider, format, args); @@ -155,20 +162,16 @@ namespace Newtonsoft.Json.Utilities if (!char.IsUpper(s[0])) return s; - int length = s.Length; char[] chars = s.ToCharArray(); -#if !(NETFX_CORE || PORTABLE) - CultureInfo invariantCulture = CultureInfo.InvariantCulture; -#endif - for (int i = 0; i < length; i++) + for (int i = 0; i < chars.Length; i++) { - bool hasNext = (i + 1 < length); + bool hasNext = (i + 1 < chars.Length); if (i > 0 && hasNext && !char.IsUpper(chars[i + 1])) break; #if !(NETFX_CORE || PORTABLE) - chars[i] = char.ToLower(chars[i], invariantCulture); + chars[i] = char.ToLower(chars[i], CultureInfo.InvariantCulture); #else chars[i] = char.ToLower(chars[i]); #endif @@ -197,13 +200,12 @@ namespace Newtonsoft.Json.Utilities public static bool StartsWith(this string source, char value) { - return (source.Length != 0 && source[0] == value); + return (source.Length > 0 && source[0] == value); } public static bool EndsWith(this string source, char value) { - int sourceLen = source.Length; - return (sourceLen != 0 && source[sourceLen - 1] == value); + return (source.Length > 0 && source[source.Length - 1] == value); } } } \ No newline at end of file