|
1 | 1 | #!/usr/bin/env python
|
2 |
| -from __future__ import print_function |
3 | 2 | import pyperf
|
4 |
| -from kafka.vendor import six |
5 | 3 |
|
6 | 4 |
|
7 | 5 | test_data = [
|
|
67 | 65 | BENCH_VALUES_DEC = list(map(bytearray, BENCH_VALUES_DEC))
|
68 | 66 |
|
69 | 67 |
|
| 68 | +def int2byte(i): |
| 69 | + return bytes((i),) |
| 70 | + |
| 71 | + |
70 | 72 | def _assert_valid_enc(enc_func):
|
71 | 73 | for encoded, decoded in test_data:
|
72 | 74 | assert enc_func(decoded) == encoded, decoded
|
@@ -116,7 +118,7 @@ def encode_varint_1(num):
|
116 | 118 | _assert_valid_enc(encode_varint_1)
|
117 | 119 |
|
118 | 120 |
|
119 |
| -def encode_varint_2(value, int2byte=six.int2byte): |
| 121 | +def encode_varint_2(value, int2byte=int2byte): |
120 | 122 | value = (value << 1) ^ (value >> 63)
|
121 | 123 |
|
122 | 124 | bits = value & 0x7f
|
@@ -151,7 +153,7 @@ def encode_varint_3(value, buf):
|
151 | 153 | assert res == encoded
|
152 | 154 |
|
153 | 155 |
|
154 |
| -def encode_varint_4(value, int2byte=six.int2byte): |
| 156 | +def encode_varint_4(value, int2byte=int2byte): |
155 | 157 | value = (value << 1) ^ (value >> 63)
|
156 | 158 |
|
157 | 159 | if value <= 0x7f: # 1 byte
|
@@ -301,22 +303,13 @@ def size_of_varint_2(value):
|
301 | 303 | _assert_valid_size(size_of_varint_2)
|
302 | 304 |
|
303 | 305 |
|
304 |
| -if six.PY3: |
305 |
| - def _read_byte(memview, pos): |
306 |
| - """ Read a byte from memoryview as an integer |
307 |
| -
|
308 |
| - Raises: |
309 |
| - IndexError: if position is out of bounds |
310 |
| - """ |
311 |
| - return memview[pos] |
312 |
| -else: |
313 |
| - def _read_byte(memview, pos): |
314 |
| - """ Read a byte from memoryview as an integer |
| 306 | +def _read_byte(memview, pos): |
| 307 | + """ Read a byte from memoryview as an integer |
315 | 308 |
|
316 | 309 | Raises:
|
317 | 310 | IndexError: if position is out of bounds
|
318 | 311 | """
|
319 |
| - return ord(memview[pos]) |
| 312 | + return memview[pos] |
320 | 313 |
|
321 | 314 |
|
322 | 315 | def decode_varint_1(buffer, pos=0):
|
|
0 commit comments