[pypy-dev] Re: [pypy-svn] r8642 - pypy/dist/pypy/objspace/std

Christian Tismer tismer at stackless.com
Fri Jan 28 02:32:43 CET 2005


ludal at 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 at 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/



More information about the Pypy-dev mailing list