[pypy-commit] pypy rdict-experiments-3: (fijal, arigo) ll_dict_contains

fijal noreply at buildbot.pypy.org
Thu Oct 10 12:05:35 CEST 2013


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: rdict-experiments-3
Changeset: r67278:9da9581079b8
Date: 2013-10-10 12:04 +0200
http://bitbucket.org/pypy/pypy/changeset/9da9581079b8/

Log:	(fijal, arigo) ll_dict_contains

diff --git a/rpython/rtyper/lltypesystem/rdict.py b/rpython/rtyper/lltypesystem/rdict.py
--- a/rpython/rtyper/lltypesystem/rdict.py
+++ b/rpython/rtyper/lltypesystem/rdict.py
@@ -376,7 +376,7 @@
     def rtype_contains((r_dict, r_key), hop):
         v_dict, v_key = hop.inputargs(r_dict, r_dict.key_repr)
         hop.exception_is_here()
-        return hop.gendirectcall(ll_contains, v_dict, v_key)
+        return hop.gendirectcall(ll_dict_contains, v_dict, v_key)
 
 class __extend__(pairtype(DictRepr, DictRepr)):
     def convert_from_to((r_dict1, r_dict2), v, llops):
@@ -1076,9 +1076,9 @@
 ll_dict_values = _make_ll_keys_values_items('values')
 ll_dict_items  = _make_ll_keys_values_items('items')
 
-def ll_contains(d, key):
-    i = ll_dict_lookup(d, key, d.keyhash(key))
-    return not i & HIGHEST_BIT
+def ll_dict_contains(d, key):
+    i = d.lookup_function(d, key, d.keyhash(key), FLAG_LOOKUP)
+    return i != -1
 
 def _ll_getnextitem(dic):
     if dic.num_items == 0:
diff --git a/rpython/rtyper/test/test_rdict.py b/rpython/rtyper/test/test_rdict.py
--- a/rpython/rtyper/test/test_rdict.py
+++ b/rpython/rtyper/test/test_rdict.py
@@ -177,6 +177,12 @@
             for k in foreach_index(ll_d):
                 assert k < rdict.VALID_OFFSET
 
+    def test_contains(self):
+        DICT = self._get_str_dict()
+        ll_d = rdict.ll_newdict(DICT)
+        rdict.ll_dict_setitem(ll_d, llstr("k"), 1)
+        assert rdict.ll_dict_contains(ll_d, llstr("k"))
+        assert not rdict.ll_dict_contains(ll_d, llstr("j"))
 
 class TestRDictDirectDummyKey(TestRDictDirect):
     class dummykeyobj:


More information about the pypy-commit mailing list