Commit 24856db0 authored by temporal's avatar temporal

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

parent 6fdb0964
...@@ -36,3 +36,5 @@ Maven packaging: ...@@ -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>
...@@ -101,11 +101,10 @@ class OutputStream(object): ...@@ -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."""
......
...@@ -87,7 +87,7 @@ def ZigZagEncode(value): ...@@ -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):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment