浏览代码

PR feedback

James Newton-King 4 年之前
父节点
当前提交
c2b22b90fc
共有 1 个文件被更改,包括 2 次插入3 次删除
  1. 2 3
      csharp/src/Google.Protobuf/WritingPrimitives.cs

+ 2 - 3
csharp/src/Google.Protobuf/WritingPrimitives.cs

@@ -172,9 +172,8 @@ namespace Google.Protobuf
             // This saves calling GetByteCount on the string. We get the string length from GetBytes.
             // 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)
             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;
                 return;
             }
             }