diff --git a/csharp/src/ProtocolBuffers/CodedOutputStream.cs b/csharp/src/ProtocolBuffers/CodedOutputStream.cs index c817a20b4c..f55f8ca2f7 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);