From 45c8850389025a28213bc5a8cdd536138693feba Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 29 Jun 2020 09:46:06 +0200 Subject: [PATCH] use BinaryPrimitives.WriteUInt64LittleEndian --- csharp/src/Google.Protobuf/WritingPrimitives.cs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/csharp/src/Google.Protobuf/WritingPrimitives.cs b/csharp/src/Google.Protobuf/WritingPrimitives.cs index 4ccad7376d..846df73502 100644 --- a/csharp/src/Google.Protobuf/WritingPrimitives.cs +++ b/csharp/src/Google.Protobuf/WritingPrimitives.cs @@ -384,18 +384,8 @@ namespace Google.Protobuf } else { - // TODO(jtattermusch): According to the benchmarks, writing byte-by-byte is actually faster - // than using BinaryPrimitives.WriteUInt64LittleEndian. - // This is strange especially because WriteUInt32LittleEndian seems to be much faster - // in terms of throughput. - buffer[state.position++] = ((byte)value); - buffer[state.position++] = ((byte)(value >> 8)); - buffer[state.position++] = ((byte)(value >> 16)); - buffer[state.position++] = ((byte)(value >> 24)); - buffer[state.position++] = ((byte)(value >> 32)); - buffer[state.position++] = ((byte)(value >> 40)); - buffer[state.position++] = ((byte)(value >> 48)); - buffer[state.position++] = ((byte)(value >> 56)); + BinaryPrimitives.WriteUInt64LittleEndian(buffer.Slice(state.position), value); + state.position += length; } }