Commits

Gora Khargosh committed f4d1ab2

Nope. That's something up with pypy.

Signed-off-by: Gora Khargosh <gora.khargosh@gmail.com>

Comments (0)

Files changed (2)

mom/codec/_alt_base.py

 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+from array import array
 
 import re
 from struct import pack
     return uint128
 
 
-
 def ipv6_b85encode_naive(uint128,
                          _base85_bytes=RFC1924_BYTES):
     """
         A 128-bit unsigned integer to be encoded.
     :param _base85_bytes:
         (Internal) Base85 encoding charset lookup table.
-    :param _pow_85:
-        (Internal) Powers of 85 lookup table.
     :returns:
         RFC1924 Base85-encoded string.
     """
     if uint128 > UINT128_MAX:
         raise OverflowError("Number is not a 128-bit unsigned integer: %d" %
                             uint128)
-#    encoded = list(range(20))
-#    for i in reversed(encoded):
-#        uint128, remainder = divmod(uint128, 85)
-#        encoded[i] = _base85_chars[remainder]
-    # Above loop unrolled:
-    # pack('B' * 20, ...)
-    return pack('BBBBBBBBBBBBBBBBBBBB',
-        _base85_bytes[(uint128 // POW_85[19])], # Don't need %85. Already < 85
-        _base85_bytes[(uint128 // POW_85[18]) % 85],
-        _base85_bytes[(uint128 // POW_85[17]) % 85],
-        _base85_bytes[(uint128 // POW_85[16]) % 85],
-        _base85_bytes[(uint128 // POW_85[15]) % 85],
-        _base85_bytes[(uint128 // POW_85[14]) % 85],
-        _base85_bytes[(uint128 // POW_85[13]) % 85],
-        _base85_bytes[(uint128 // POW_85[12]) % 85],
-        _base85_bytes[(uint128 // POW_85[11]) % 85],
-        _base85_bytes[(uint128 // POW_85[10]) % 85],
-        _base85_bytes[(uint128 // POW_85[9]) % 85],
-        _base85_bytes[(uint128 // POW_85[8]) % 85],
-        _base85_bytes[(uint128 // POW_85[7]) % 85],
-        _base85_bytes[(uint128 // POW_85[6]) % 85],
-        _base85_bytes[(uint128 // POW_85[5]) % 85],
-        _base85_bytes[(uint128 // POW_85[4]) % 85],
-        _base85_bytes[(uint128 // POW_85[3]) % 85],
-        _base85_bytes[(uint128 // POW_85[2]) % 85],
-        _base85_bytes[(uint128 // 85) % 85],   #85**1 == 85
-        _base85_bytes[uint128 % 85],           #85**0 == 1
-    )
+    #encoded = list(range(20))
+    encoded = array('B', list(range(20)))
+    for i in reversed(encoded):
+        uint128, remainder = divmod(uint128, 85)
+        encoded[i] = _base85_bytes[remainder]
+    return encoded.tostring()

mom/codec/base85.py

         A 128-bit unsigned integer to be encoded.
     :param _base85_bytes:
         (Internal) Base85 encoding charset lookup table.
+    :param _pow_85:
+        (Internal) Powers of 85 lookup table.
     :returns:
         RFC1924 Base85-encoded string.
     """
     if uint128 > UINT128_MAX:
         raise OverflowError("Number is not a 128-bit unsigned integer: %d" %
                             uint128)
-    #encoded = list(range(20))
-    encoded = array('B', list(range(20)))
-    for i in reversed(encoded):
-        uint128, remainder = divmod(uint128, 85)
-        encoded[i] = _base85_bytes[remainder]
-    return encoded.tostring()
+#    encoded = list(range(20))
+#    for i in reversed(encoded):
+#        uint128, remainder = divmod(uint128, 85)
+#        encoded[i] = _base85_chars[remainder]
+    # Above loop unrolled:
+    # pack('B' * 20, ...)
+    return pack('BBBBBBBBBBBBBBBBBBBB',
+        _base85_bytes[(uint128 // POW_85[19])], # Don't need %85. Already < 85
+        _base85_bytes[(uint128 // POW_85[18]) % 85],
+        _base85_bytes[(uint128 // POW_85[17]) % 85],
+        _base85_bytes[(uint128 // POW_85[16]) % 85],
+        _base85_bytes[(uint128 // POW_85[15]) % 85],
+        _base85_bytes[(uint128 // POW_85[14]) % 85],
+        _base85_bytes[(uint128 // POW_85[13]) % 85],
+        _base85_bytes[(uint128 // POW_85[12]) % 85],
+        _base85_bytes[(uint128 // POW_85[11]) % 85],
+        _base85_bytes[(uint128 // POW_85[10]) % 85],
+        _base85_bytes[(uint128 // POW_85[9]) % 85],
+        _base85_bytes[(uint128 // POW_85[8]) % 85],
+        _base85_bytes[(uint128 // POW_85[7]) % 85],
+        _base85_bytes[(uint128 // POW_85[6]) % 85],
+        _base85_bytes[(uint128 // POW_85[5]) % 85],
+        _base85_bytes[(uint128 // POW_85[4]) % 85],
+        _base85_bytes[(uint128 // POW_85[3]) % 85],
+        _base85_bytes[(uint128 // POW_85[2]) % 85],
+        _base85_bytes[(uint128 // 85) % 85],   #85**1 == 85
+        _base85_bytes[uint128 % 85],           #85**0 == 1
+    )
 
 
 def ipv6_b85decode(encoded,