# HG changeset patch # User Mads Kiilerich # Date 1236205439 -3600 # Node ID 2505e9f84153f6a5b513f06fb176417834588a38 # Parent 6542be5df71969ab4b2942539bfb86d3cca07f17 Optimization of pure.base85.b85encode This makes pure python base85 encoding 3x faster than before. Now it is only 40x slower than the C version. diff -r 6542be5df719 -r 2505e9f84153 mercurial/pure/base85.py --- a/mercurial/pure/base85.py Wed Mar 04 19:04:21 2009 -0600 +++ b/mercurial/pure/base85.py Wed Mar 04 23:23:59 2009 +0100 @@ -9,6 +9,7 @@ _b85chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" \ "abcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~" +_b85chars2 = [(a + b) for a in _b85chars for b in _b85chars] _b85dec = {} def _mkb85dec(): @@ -22,24 +23,13 @@ if r: text += '\0' * (4 - r) longs = len(text) >> 2 - out = [] words = struct.unpack('>%dL' % (longs), text) - for word in words: - # unrolling improved speed by 33% - word, r = divmod(word, 85) - e = _b85chars[r] - word, r = divmod(word, 85) - d = _b85chars[r] - word, r = divmod(word, 85) - c = _b85chars[r] - word, r = divmod(word, 85) - b = _b85chars[r] - word, r = divmod(word, 85) - a = _b85chars[r] - out += (a, b, c, d, e) + out = ''.join(_b85chars[(word / 52200625) % 85] + + _b85chars2[(word / 7225) % 7225] + + _b85chars2[word % 7225] + for word in words) - out = ''.join(out) if pad: return out