[MERGE] rand_chars() optimization

John Arbash Meinel john at arbash-meinel.com
Tue Mar 13 18:54:41 GMT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Marius Gedminas wrote:
> On Sun, Mar 11, 2007 at 04:39:43PM +0300, Dmitry Vasiliev wrote:
>>> I suspect it might be a bit faster if you used a string rather than a
>>> dict here:
>>>
>>>  _rand_chars_map = ALNUM * (255 / len(ALNUM) + 1)
>> But how it may helps to make rand_chars() any faster? With 
>> _rand_chars_map as a dict you just can do later _rand_chars_map[raw_byte].
> 
> You can do the same with a string, only instead of a hash table lookup
> that would translate to an array reference.
> 
> Uh, that's assuming raw_byte is actually a byte (int) and not a char.
> If it's a char, then my suggestion doesn't make sense (but then I
> suggest that the variable might be misnamed).
> 
> Marius Gedminas

No, it is a 'byte' which is not an int. it is 8-bits, ie 'char' in C,
which in python is a 'str' of length 1.

Which is why we can't use a string. You could do 'ord(rand_byte)', but I
have the feeling you would lose any benefit of having a string.

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF9vNxJdeBCYSNAAMRAjsvAKCd10GYvdwXeubvkE1z1ScvYyJskACgzHFw
HAdrtJSabd+QTUpPEIMxIRU=
=QxX6
-----END PGP SIGNATURE-----



More information about the bazaar mailing list