From de82488549d724c2f2cef3511e81d7a5305312fc Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Mon, 9 Jan 2017 16:46:11 +1300 Subject: [PATCH] -Minor code cleanup -Fixed CA warning --- Src/Newtonsoft.Json.Tests/PerformanceTests.cs | 4 +- Src/Newtonsoft.Json/Linq/JTokenReader.cs | 4 +- Src/Newtonsoft.Json/Linq/JValue.cs | 4 +- .../Utilities/JavaScriptUtils.cs | 65 +++++++++---------- 4 files changed, 37 insertions(+), 40 deletions(-) diff --git a/Src/Newtonsoft.Json.Tests/PerformanceTests.cs b/Src/Newtonsoft.Json.Tests/PerformanceTests.cs index 7dacd84c..6dcbaaf2 100644 --- a/Src/Newtonsoft.Json.Tests/PerformanceTests.cs +++ b/Src/Newtonsoft.Json.Tests/PerformanceTests.cs @@ -70,8 +70,8 @@ namespace Newtonsoft.Json.Tests #if DEBUG public int Iterations = 1; #else - //public int Iterations = 100; - public int Iterations = 10000; + public int Iterations = 100; + //public int Iterations = 10000; #endif #region Data diff --git a/Src/Newtonsoft.Json/Linq/JTokenReader.cs b/Src/Newtonsoft.Json/Linq/JTokenReader.cs index ecac9e12..4ed06b27 100644 --- a/Src/Newtonsoft.Json/Linq/JTokenReader.cs +++ b/Src/Newtonsoft.Json/Linq/JTokenReader.cs @@ -140,7 +140,7 @@ namespace Newtonsoft.Json.Linq case JTokenType.Property: return null; default: - throw MiscellaneousUtils.CreateArgumentOutOfRangeException("Type", c.Type, "Unexpected JContainer type."); + throw MiscellaneousUtils.CreateArgumentOutOfRangeException(nameof(c.Type), c.Type, "Unexpected JContainer type."); } } @@ -234,7 +234,7 @@ namespace Newtonsoft.Json.Linq SetToken(JsonToken.String, SafeToString(((JValue)token).Value)); break; default: - throw MiscellaneousUtils.CreateArgumentOutOfRangeException("Type", token.Type, "Unexpected JTokenType."); + throw MiscellaneousUtils.CreateArgumentOutOfRangeException(nameof(token.Type), token.Type, "Unexpected JTokenType."); } } diff --git a/Src/Newtonsoft.Json/Linq/JValue.cs b/Src/Newtonsoft.Json/Linq/JValue.cs index 372702a8..bf2a7643 100644 --- a/Src/Newtonsoft.Json/Linq/JValue.cs +++ b/Src/Newtonsoft.Json/Linq/JValue.cs @@ -392,7 +392,7 @@ namespace Newtonsoft.Json.Linq return ts1.CompareTo(ts2); default: - throw MiscellaneousUtils.CreateArgumentOutOfRangeException("valueType", valueType, "Unexpected value type: {0}".FormatWith(CultureInfo.InvariantCulture, valueType)); + throw MiscellaneousUtils.CreateArgumentOutOfRangeException(nameof(valueType), valueType, "Unexpected value type: {0}".FormatWith(CultureInfo.InvariantCulture, valueType)); } } @@ -823,7 +823,7 @@ namespace Newtonsoft.Json.Linq return; } - throw MiscellaneousUtils.CreateArgumentOutOfRangeException("TokenType", _valueType, "Unexpected token type."); + throw MiscellaneousUtils.CreateArgumentOutOfRangeException(nameof(Type), _valueType, "Unexpected token type."); } internal override int GetDeepHashCode() diff --git a/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs b/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs index 6e3ee247..b3da74b4 100644 --- a/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs @@ -140,38 +140,6 @@ namespace Newtonsoft.Json.Utilities return false; } - private static int FirstCharToEscape(string s, bool[] charEscapeFlags, StringEscapeHandling stringEscapeHandling) - { - for (int i = 0; i != s.Length; i++) - { - char c = s[i]; - - if (c < charEscapeFlags.Length) - { - if (charEscapeFlags[c]) - { - return i; - } - } - else if (stringEscapeHandling == StringEscapeHandling.EscapeNonAscii) - { - return i; - } - else - { - switch (c) - { - case '\u0085': - case '\u2028': - case '\u2029': - return i; - } - } - } - - return -1; - } - public static void WriteEscapedJavaScriptString(TextWriter writer, string s, char delimiter, bool appendDelimiters, bool[] charEscapeFlags, StringEscapeHandling stringEscapeHandling, IArrayPool bufferPool, ref char[] writeBuffer) { @@ -349,6 +317,37 @@ namespace Newtonsoft.Json.Utilities } #if !(NET20 || NET35 || NET40 || PORTABLE40) + private static int FirstCharToEscape(string s, bool[] charEscapeFlags, StringEscapeHandling stringEscapeHandling) + { + for (int i = 0; i != s.Length; i++) + { + char c = s[i]; + + if (c < charEscapeFlags.Length) + { + if (charEscapeFlags[c]) + { + return i; + } + } + else if (stringEscapeHandling == StringEscapeHandling.EscapeNonAscii) + { + return i; + } + else + { + switch (c) + { + case '\u0085': + case '\u2028': + case '\u2029': + return i; + } + } + } + + return -1; + } public static Task WriteEscapedJavaScriptStringAsync(TextWriter writer, string s, char delimiter, bool appendDelimiters, bool[] charEscapeFlags, StringEscapeHandling stringEscapeHandling, JsonTextWriter client, char[] writeBuffer, CancellationToken cancellationToken = default(CancellationToken)) { @@ -521,8 +520,6 @@ namespace Newtonsoft.Json.Utilities await writer.WriteAsync(writeBuffer, 0, length, cancellationToken).ConfigureAwait(false); } } - #endif - } } \ No newline at end of file