[pypy-commit] pypy keys_with_hash: the r_dict case

arigo noreply at buildbot.pypy.org
Tue Sep 1 10:38:54 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: keys_with_hash
Changeset: r79338:e898f825312b
Date: 2015-09-01 10:39 +0200
http://bitbucket.org/pypy/pypy/changeset/e898f825312b/

Log:	the r_dict case

diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -790,7 +790,7 @@
 
 def _expected_hash(d, key):
     if isinstance(d, r_dict):
-        xxx
+        return d.key_hash(key)
     else:
         return compute_hash(key)
 
diff --git a/rpython/rlib/test/test_objectmodel.py b/rpython/rlib/test/test_objectmodel.py
--- a/rpython/rlib/test/test_objectmodel.py
+++ b/rpython/rlib/test/test_objectmodel.py
@@ -636,6 +636,24 @@
     res = interpret(f, [27])
     assert res == 42
 
+def test_rdict_with_hash():
+    def f(i):
+        d = r_dict(strange_key_eq, strange_key_hash)
+        h = strange_key_hash("abc")
+        assert h == strange_key_hash("aXX") and strange_key_eq("abc", "aXX")
+        setitem_with_hash(d, "abc", h, i)
+        assert getitem_with_hash(d, "aXX", h) == i
+        try:
+            getitem_with_hash(d, "bYY", strange_key_hash("bYY"))
+        except KeyError:
+            pass
+        else:
+            raise AssertionError
+        return 0
+
+    assert f(29) == 0
+    interpret(f, [27])
+
 def test_import_from_mixin():
     class M:    # old-style
         def f(self): pass


More information about the pypy-commit mailing list