From ce0e348ded9cb7e180588476ebb5a8f3e0460f4e Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Thu, 11 Jun 2015 14:32:19 +0100 Subject: Optimize WriteRawInt32 for the common case of a value < 128, which is a single byte. Aside from anything else, this will be used for all tags for fields 1-15. --- csharp/src/ProtocolBuffers/CodedOutputStream.cs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'csharp/src') diff --git a/csharp/src/ProtocolBuffers/CodedOutputStream.cs b/csharp/src/ProtocolBuffers/CodedOutputStream.cs index c817a20b..f55f8ca2 100644 --- a/csharp/src/ProtocolBuffers/CodedOutputStream.cs +++ b/csharp/src/ProtocolBuffers/CodedOutputStream.cs @@ -1033,6 +1033,13 @@ namespace Google.Protobuf /// public void WriteRawVarint32(uint value) { + // Optimize for the common case of a single byte value + if (value < 128 && position < limit) + { + buffer[position++] = (byte)value; + return; + } + while (value > 127 && position < limit) { buffer[position++] = (byte) ((value & 0x7F) | 0x80); -- cgit v1.2.3