##// END OF EJS Templates
Optimization of pure.base85.b85encode...
Mads Kiilerich -
r7835:2505e9f8 default
parent child Browse files
Show More
@@ -9,6 +9,7 b' import struct'
9 9
10 10 _b85chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
11 11 "abcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~"
12 _b85chars2 = [(a + b) for a in _b85chars for b in _b85chars]
12 13 _b85dec = {}
13 14
14 15 def _mkb85dec():
@@ -22,24 +23,13 b' def b85encode(text, pad=False):'
22 23 if r:
23 24 text += '\0' * (4 - r)
24 25 longs = len(text) >> 2
25 out = []
26 26 words = struct.unpack('>%dL' % (longs), text)
27 for word in words:
28 # unrolling improved speed by 33%
29 word, r = divmod(word, 85)
30 e = _b85chars[r]
31 word, r = divmod(word, 85)
32 d = _b85chars[r]
33 word, r = divmod(word, 85)
34 c = _b85chars[r]
35 word, r = divmod(word, 85)
36 b = _b85chars[r]
37 word, r = divmod(word, 85)
38 a = _b85chars[r]
39 27
40 out += (a, b, c, d, e)
28 out = ''.join(_b85chars[(word / 52200625) % 85] +
29 _b85chars2[(word / 7225) % 7225] +
30 _b85chars2[word % 7225]
31 for word in words)
41 32
42 out = ''.join(out)
43 33 if pad:
44 34 return out
45 35
General Comments 0
You need to be logged in to leave comments. Login now