[pypy-svn] r39791 - in pypy/branch/rope-branch/pypy/objspace/std: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Sat Mar 3 13:48:25 CET 2007
Author: cfbolz
Date: Sat Mar 3 13:48:23 2007
New Revision: 39791
Modified:
pypy/branch/rope-branch/pypy/objspace/std/rope.py
pypy/branch/rope-branch/pypy/objspace/std/test/test_rope.py
Log:
use the rpython hash cache when hashing LiteralStringNode
Modified: pypy/branch/rope-branch/pypy/objspace/std/rope.py
==============================================================================
--- pypy/branch/rope-branch/pypy/objspace/std/rope.py (original)
+++ pypy/branch/rope-branch/pypy/objspace/std/rope.py Sat Mar 3 13:48:23 2007
@@ -767,9 +767,19 @@
def hash_rope(rope):
from pypy.rlib.rarithmetic import intmask
+ from pypy.rlib.objectmodel import we_are_translated
length = rope.length()
if length == 0:
x = -1
+ elif isinstance(rope, LiteralStringNode):
+ if we_are_translated():
+ x = hash(s) # to use the hash cache in rpython strings
+ else:
+ # to make sure we get the same hash as rpython (otherwise
+ # translation will freeze W_DictObjects where we can't find the
+ # keys any more!)
+ x = _hash_string(s)
+ return hash(rope.s)
else:
x = ord(rope.getitem(0)) << 7
iter = CharIterator(rope)
Modified: pypy/branch/rope-branch/pypy/objspace/std/test/test_rope.py
==============================================================================
--- pypy/branch/rope-branch/pypy/objspace/std/test/test_rope.py (original)
+++ pypy/branch/rope-branch/pypy/objspace/std/test/test_rope.py Sat Mar 3 13:48:23 2007
@@ -293,8 +293,9 @@
def test_hash():
from pypy.rlib.rarithmetic import _hash_string
- rope, st = make_random_string()
- assert hash_rope(rope) == _hash_string(st)
+ for i in range(10):
+ rope, st = make_random_string()
+ assert hash_rope(rope) == _hash_string(st)
def test_equality():
l = [make_random_string() for i in range(3)]
More information about the Pypy-commit
mailing list