Index: trunk/python/google/protobuf/internal/wire_format.py
===================================================================
--- trunk/python/google/protobuf/internal/wire_format.py	(revision 91)
+++ trunk/python/google/protobuf/internal/wire_format.py	(working copy)
@@ -224,13 +224,19 @@
 
 
 def _VarUInt64ByteSizeNoTag(uint64):
-  """Returns the bytes required to serialize a single varint.
+  """Returns the number of bytes required to serialize a single varint
+  using boundary value comparisons. (unrolled loop optimization -WPierce)
   uint64 must be unsigned.
   """
+  if uint64 < (1<< 7): return 1
+  if uint64 < (1<<14): return 2
+  if uint64 < (1<<21): return 3
+  if uint64 < (1<<28): return 4
+  if uint64 < (1<<35): return 5
+  if uint64 < (1<<42): return 6
+  if uint64 < (1<<49): return 7
+  if uint64 < (1<<56): return 8
+  if uint64 < (1<<63): return 9
   if uint64 > UINT64_MAX:
     raise message.EncodeError('Value out of range: %d' % uint64)
-  bytes = 1
-  while uint64 > 0x7f:
-    bytes += 1
-    uint64 >>= 7
-  return bytes
+  return 10
