Browse Source

Add comments

James Newton-King 4 years ago
parent
commit
e4cd821f21

+ 2 - 0
csharp/src/Google.Protobuf.Test/JsonParserTest.cs

@@ -551,6 +551,8 @@ namespace Google.Protobuf
         }
         }
 
 
         [Test]
         [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
 #if !NET5_0
         [TestCase("1.7977e308")]
         [TestCase("1.7977e308")]
         [TestCase("-1.7977e308")]
         [TestCase("-1.7977e308")]

+ 2 - 0
csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs

@@ -199,6 +199,8 @@ namespace Google.Protobuf
         [TestCase("1e-")]
         [TestCase("1e-")]
         [TestCase("--")]
         [TestCase("--")]
         [TestCase("--1")]
         [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
 #if !NET5_0
         [TestCase("-1.7977e308")]
         [TestCase("-1.7977e308")]
         [TestCase("1.7977e308")]
         [TestCase("1.7977e308")]

+ 5 - 0
csharp/src/Google.Protobuf/WritingPrimitives.cs

@@ -213,6 +213,8 @@ namespace Google.Protobuf
             }
             }
         }
         }
 
 
+        // 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<byte> buffer, ref WriterInternalState state, string value, int length)
         private static void WriteAsciiStringToBuffer(Span<byte> buffer, ref WriterInternalState state, string value, int length)
         {
         {
             ref char sourceChars = ref MemoryMarshal.GetReference(value.AsSpan());
             ref char sourceChars = ref MemoryMarshal.GetReference(value.AsSpan());
@@ -283,6 +285,9 @@ namespace Google.Protobuf
             else
             else
 #endif
 #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)
                 if (BitConverter.IsLittleEndian)
                 {
                 {
                     outputBuffer = (byte)value;
                     outputBuffer = (byte)value;