diff --git a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs index 87a389aecbb5..69c9eb6e998b 100644 --- a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs @@ -551,6 +551,8 @@ public void NumberToDouble_Valid(string jsonValue, double expectedParsedValue) } [Test] + // Skip these test cases in .NET 5 because floating point parsing supports bigger values. + // These big values won't throw an error in the test. #if !NET5_0 [TestCase("1.7977e308")] [TestCase("-1.7977e308")] diff --git a/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs b/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs index 55ec02ea023f..0cbc0a4ff8ec 100644 --- a/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs @@ -199,6 +199,8 @@ public void NumberValue(string json, double expectedValue) [TestCase("1e-")] [TestCase("--")] [TestCase("--1")] + // Skip these test cases in .NET 5 because floating point parsing supports bigger values. + // These big values won't throw an error in the test. #if !NET5_0 [TestCase("-1.7977e308")] [TestCase("1.7977e308")] diff --git a/csharp/src/Google.Protobuf/WritingPrimitives.cs b/csharp/src/Google.Protobuf/WritingPrimitives.cs index d33a298d3e7f..8beefc54c574 100644 --- a/csharp/src/Google.Protobuf/WritingPrimitives.cs +++ b/csharp/src/Google.Protobuf/WritingPrimitives.cs @@ -213,6 +213,8 @@ public static void WriteString(ref Span buffer, ref WriterInternalState st } } + // Calling this method with non-ASCII content will break. + // Content must be verified to be all ASCII before using this method. private static void WriteAsciiStringToBuffer(Span buffer, ref WriterInternalState state, string value, int length) { ref char sourceChars = ref MemoryMarshal.GetReference(value.AsSpan()); @@ -283,6 +285,9 @@ private static void NarrowFourUtf16CharsToAsciiAndWriteToBuffer(ref byte outputB else #endif { + // Fallback to non-SIMD approach when SIMD is not available. + // This could happen either because the APIs are not available, or hardware doesn't support it. + // Processing 4 chars at a time in this fallback is still faster than casting one char at a time. if (BitConverter.IsLittleEndian) { outputBuffer = (byte)value;