From fc8da05002ac3c4da26339349746a1d2c28ad153 Mon Sep 17 00:00:00 2001
From: David Raila <raila@illinois.edu>
Date: Sun, 27 Jul 2008 18:38:54 +0000
Subject: [PATCH] Applied Ulrich Kunitz's patches to slightly optimize Python
 serialization code.

---
 CONTRIBUTORS.txt                                 | 2 ++
 python/google/protobuf/internal/output_stream.py | 5 ++---
 python/google/protobuf/internal/wire_format.py   | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index 4738f51..0772fd6 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -36,3 +36,5 @@ Maven packaging:
 
 Non-Google patch contributors:
   Kevin Ko <kevin.s.ko@gmail.com>
+  Johan Euphrosine <proppy@aminche.com>
+  Ulrich Kunitz <kune@deine-taler.de>
diff --git a/python/google/protobuf/internal/output_stream.py b/python/google/protobuf/internal/output_stream.py
index 767e972..ccb9122 100755
--- a/python/google/protobuf/internal/output_stream.py
+++ b/python/google/protobuf/internal/output_stream.py
@@ -101,11 +101,10 @@ class OutputStream(object):
     while True:
       bits = unsigned_value & 0x7f
       unsigned_value >>= 7
-      if unsigned_value:
-        bits |= 0x80
-      self._buffer.append(bits)
       if not unsigned_value:
+        self._buffer.append(bits)
         break
+      self._buffer.append(0x80|bits)
 
   def ToString(self):
     """Returns a string containing the bytes in our internal buffer."""
diff --git a/python/google/protobuf/internal/wire_format.py b/python/google/protobuf/internal/wire_format.py
index 69aa4ab..ea219e2 100755
--- a/python/google/protobuf/internal/wire_format.py
+++ b/python/google/protobuf/internal/wire_format.py
@@ -87,7 +87,7 @@ def ZigZagEncode(value):
   """
   if value >= 0:
     return value << 1
-  return ((value << 1) ^ (~0)) | 0x1
+  return (value << 1) ^ (~0)
 
 
 def ZigZagDecode(value):
-- 
GitLab