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.
pull/515/head
Jon Skeet 10 years ago
parent 35e4dbd518
commit ce0e348ded
  1. 7
      csharp/src/ProtocolBuffers/CodedOutputStream.cs

@ -1033,6 +1033,13 @@ namespace Google.Protobuf
/// </summary>
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);

Loading…
Cancel
Save