From 93fafb03bed73ec927f17b9e74cdc445a3316522 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Fri, 29 Jan 2021 12:06:14 +1300 Subject: [PATCH] Comment --- csharp/src/Google.Protobuf/WritingPrimitives.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/csharp/src/Google.Protobuf/WritingPrimitives.cs b/csharp/src/Google.Protobuf/WritingPrimitives.cs index 8d8dccc394ad..b6ed90cdf5f6 100644 --- a/csharp/src/Google.Protobuf/WritingPrimitives.cs +++ b/csharp/src/Google.Protobuf/WritingPrimitives.cs @@ -202,7 +202,8 @@ public static void WriteString(ref Span buffer, ref WriterInternalState st ? WriteAsciiStringToBuffer(ref sourceChars, ref destinationBytes, value, length) : 0; - // This avoids bound checks + // Process any remaining, 1 char at a time. + // Avoid bounds checking with ref + Unsafe for (; currentIndex < length; currentIndex++) { Unsafe.AddByteOffset(ref destinationBytes, (IntPtr)currentIndex) = (byte)Unsafe.AddByteOffset(ref sourceChars, (IntPtr)(currentIndex * 2));