Browse Source

Applied Ulrich Kunitz's patches to slightly optimize Python serialization code.

temporal 17 years ago
parent
commit
24856db0e9

+ 2 - 0
CONTRIBUTORS.txt

@@ -36,3 +36,5 @@ Maven packaging:
 
 
 Non-Google patch contributors:
 Non-Google patch contributors:
   Kevin Ko <kevin.s.ko@gmail.com>
   Kevin Ko <kevin.s.ko@gmail.com>
+  Johan Euphrosine <proppy@aminche.com>
+  Ulrich Kunitz <kune@deine-taler.de>

+ 2 - 3
python/google/protobuf/internal/output_stream.py

@@ -101,11 +101,10 @@ class OutputStream(object):
     while True:
     while True:
       bits = unsigned_value & 0x7f
       bits = unsigned_value & 0x7f
       unsigned_value >>= 7
       unsigned_value >>= 7
-      if unsigned_value:
-        bits |= 0x80
-      self._buffer.append(bits)
       if not unsigned_value:
       if not unsigned_value:
+        self._buffer.append(bits)
         break
         break
+      self._buffer.append(0x80|bits)
 
 
   def ToString(self):
   def ToString(self):
     """Returns a string containing the bytes in our internal buffer."""
     """Returns a string containing the bytes in our internal buffer."""

+ 1 - 1
python/google/protobuf/internal/wire_format.py

@@ -87,7 +87,7 @@ def ZigZagEncode(value):
   """
   """
   if value >= 0:
   if value >= 0:
     return value << 1
     return value << 1
-  return ((value << 1) ^ (~0)) | 0x1
+  return (value << 1) ^ (~0)
 
 
 
 
 def ZigZagDecode(value):
 def ZigZagDecode(value):