Bläddra i källkod

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.

Jon Skeet 10 år sedan
förälder
incheckning
ce0e348ded
1 ändrade filer med 7 tillägg och 0 borttagningar
  1. 7 0
      csharp/src/ProtocolBuffers/CodedOutputStream.cs

+ 7 - 0
csharp/src/ProtocolBuffers/CodedOutputStream.cs

@@ -1033,6 +1033,13 @@ namespace Google.Protobuf
         /// </summary>
         /// </summary>
         public void WriteRawVarint32(uint value)
         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)
             while (value > 127 && position < limit)
             {
             {
                 buffer[position++] = (byte) ((value & 0x7F) | 0x80);
                 buffer[position++] = (byte) ((value & 0x7F) | 0x80);