Re: [pypy-svn] r8642 - pypy/dist/pypy/objspace/std
ludal@codespeak.net wrote:
Author: ludal Date: Thu Jan 27 18:06:26 2005 New Revision: 8642
Modified: pypy/dist/pypy/objspace/std/stringobject.py Log: keep a cache of the hash value of strings like CPython does
Hi! I think it is a fine idea to do the hash cache. Just a comment...:
Modified: pypy/dist/pypy/objspace/std/stringobject.py ...
def hash__String(space, w_str): - return W_IntObject(space, hash(w_str._value)) + w_hash = w_str.w_hash + if w_hash is None: + w_hash = W_IntObject(space, hash(w_str._value)) + w_str.w_hash = w_hash + return w_hash
I don't see the point why the hash should be stored as a wrapped value. IMHO, the main use of the hash is inside of dict objects. Wouldn't it make more sense to cache the unwrapped value, since we (as I think) do the hashing in a dict with an unwrapped integer, anyway? It is also more conformant with CPython, where the hash is an internal implementation detail. Maybe I just missed something, so anyway - good night! (Ludovic, I don't have your email contact) cheers - chris -- Christian Tismer :^) <mailto:tismer@stackless.com> tismerysoft GmbH : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9A : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 802 86 56 mobile +49 173 24 18 776 fax +49 30 80 90 57 05 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/
Hi Christian, On Fri, Jan 28, 2005 at 02:32:43AM +0100, Christian Tismer wrote:
I don't see the point why the hash should be stored as a wrapped value.
That's because hash__Str() must return a wrapped value, as space.hash(), and as the W_DictObject expects it. Of course it would be more efficient if somehow we passed unwrapped hash values around, but that's a kind of small optimization that doesn't really pay off the price of making Yet Another Oddity in the public methods of spaces... That said, it would also be ok to move the hack into W_DictObject instead of W_StringObject, by special-casing strings and storing an unwrapped hash cache into W_StringObject. Armin
participants (2)
-
Armin Rigo
-
Christian Tismer