From c2b22b90fc3b513e4320f441654b58c48a1793e0 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Thu, 28 Jan 2021 08:11:52 +1300 Subject: [PATCH] PR feedback --- csharp/src/Google.Protobuf/WritingPrimitives.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/csharp/src/Google.Protobuf/WritingPrimitives.cs b/csharp/src/Google.Protobuf/WritingPrimitives.cs index 777390559793..cf8fc7ba71fd 100644 --- a/csharp/src/Google.Protobuf/WritingPrimitives.cs +++ b/csharp/src/Google.Protobuf/WritingPrimitives.cs @@ -172,9 +172,8 @@ public static void WriteString(ref Span buffer, ref WriterInternalState st // This saves calling GetByteCount on the string. We get the string length from GetBytes. if (value.Length <= MaxSmallStringLength && buffer.Length - state.position - 1 >= value.Length * MaxBytesPerChar) { - // Get the original position, then increment it on state by 1, then write string to buffer. - // Method will return byte length, which is then set to the original position. - buffer[state.position++] = (byte)WriteStringToBuffer(buffer, ref state, value); + int indexOfLengthDelimiter = state.position++; + buffer[indexOfLengthDelimiter] = (byte)WriteStringToBuffer(buffer, ref state, value); return; }