From 9ca0877db1b873c14666709ebf844abf13eb8243 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 23 Jun 2020 16:55:43 +0200 Subject: [PATCH] optimize WriteRawBytes --- csharp/src/Google.Protobuf/WritingPrimitives.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/csharp/src/Google.Protobuf/WritingPrimitives.cs b/csharp/src/Google.Protobuf/WritingPrimitives.cs index ed76682bd..afa6e986e 100644 --- a/csharp/src/Google.Protobuf/WritingPrimitives.cs +++ b/csharp/src/Google.Protobuf/WritingPrimitives.cs @@ -428,7 +428,7 @@ namespace Google.Protobuf /// public static void WriteRawBytes(ref Span buffer, ref WriterInternalState state, ReadOnlySpan value) { - if (state.limit - state.position >= value.Length) + if (buffer.Length - state.position >= value.Length) { // We have room in the current buffer. value.CopyTo(buffer.Slice(state.position, value.Length)); @@ -443,9 +443,9 @@ namespace Google.Protobuf // Current this is not being done to avoid specialcasing the code for // CodedOutputStream vs IBufferWriter. int bytesWritten = 0; - while (state.limit - state.position < value.Length - bytesWritten) + while (buffer.Length - state.position < value.Length - bytesWritten) { - int length = state.limit - state.position; + int length = buffer.Length - state.position; value.Slice(bytesWritten, length).CopyTo(buffer.Slice(state.position, length)); bytesWritten += length; state.position += length;