Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Feb 15, 2021
1 parent 818c2ba commit e4cd821
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions csharp/src/Google.Protobuf.Test/JsonParserTest.cs
Expand Up @@ -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")]
Expand Down
2 changes: 2 additions & 0 deletions csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs
Expand Up @@ -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")]
Expand Down
5 changes: 5 additions & 0 deletions csharp/src/Google.Protobuf/WritingPrimitives.cs
Expand Up @@ -213,6 +213,8 @@ public static void WriteString(ref Span<byte> 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<byte> buffer, ref WriterInternalState state, string value, int length)
{
ref char sourceChars = ref MemoryMarshal.GetReference(value.AsSpan());
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e4cd821

Please sign in to comment.