diff options
author | Jon Skeet <skeet@pobox.com> | 2015-06-11 14:32:19 +0100 |
---|---|---|
committer | Jon Skeet <skeet@pobox.com> | 2015-06-11 14:32:19 +0100 |
commit | ce0e348ded9cb7e180588476ebb5a8f3e0460f4e (patch) | |
tree | fa4b9c1162a434a4628050f8c3f4972bcd70f705 /csharp | |
parent | 35e4dbd51829216fd1ad85a95c01042346b63c6b (diff) | |
download | protobuf-ce0e348ded9cb7e180588476ebb5a8f3e0460f4e.tar.gz protobuf-ce0e348ded9cb7e180588476ebb5a8f3e0460f4e.tar.bz2 protobuf-ce0e348ded9cb7e180588476ebb5a8f3e0460f4e.zip |
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.
Diffstat (limited to 'csharp')
-rw-r--r-- | csharp/src/ProtocolBuffers/CodedOutputStream.cs | 7 |
1 files changed, 7 insertions, 0 deletions
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 /// </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);
|