[pypy-svn] r8642 - pypy/dist/pypy/objspace/std

ludal at codespeak.net ludal at codespeak.net
Thu Jan 27 18:06:27 CET 2005


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


Modified: pypy/dist/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/stringobject.py	(original)
+++ pypy/dist/pypy/objspace/std/stringobject.py	Thu Jan 27 18:06:26 2005
@@ -94,6 +94,7 @@
     def __init__(w_self, space, str):
         W_Object.__init__(w_self, space)
         w_self._value = str
+        w_self.w_hash = None
 
     def __repr__(w_self):
         """ representation for debugging purposes """
@@ -771,7 +772,11 @@
     return w_str._value
 
 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
 
 
 ##EQ = 1



More information about the Pypy-commit mailing list