[pypy-svn] r13896 - in pypy/dist/pypy/rpython: . test

ac at codespeak.net ac at codespeak.net
Sat Jun 25 19:54:28 CEST 2005


Author: ac
Date: Sat Jun 25 19:54:28 2005
New Revision: 13896

Modified:
   pypy/dist/pypy/rpython/rdict.py
   pypy/dist/pypy/rpython/test/test_rdict.py
Log:
(arre + christian) Add contains to rdict.

Modified: pypy/dist/pypy/rpython/rdict.py
==============================================================================
--- pypy/dist/pypy/rpython/rdict.py	(original)
+++ pypy/dist/pypy/rpython/rdict.py	Sat Jun 25 19:54:28 2005
@@ -137,7 +137,11 @@
     def rtype_setitem((r_dict, r_string), hop):
         v_dict, v_key, v_value = hop.inputargs(r_dict, string_repr, r_dict.value_repr) 
         hop.gendirectcall(ll_strdict_setitem, v_dict, v_key, v_value)
-    
+
+    def rtype_contains((r_dict, r_string), hop):
+        v_dict, v_key = hop.inputargs(r_dict, string_repr)
+        return hop.gendirectcall(ll_contains, v_dict, v_key)
+        
 class __extend__(pairtype(StrDictRepr, StrDictRepr)):
     def convert_from_to((r_dict1, r_dict2), v, llops):
         # check that we don't convert from StrDicts with
@@ -401,3 +405,9 @@
                 p += 1
         i += 1
     return res
+
+def ll_contains(d, key): 
+    entry = ll_strdict_lookup(d, key) 
+    if entry.key and entry.key != deleted_entry_marker: 
+        return True
+    return False

Modified: pypy/dist/pypy/rpython/test/test_rdict.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rdict.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rdict.py	Sat Jun 25 19:54:28 2005
@@ -237,4 +237,9 @@
     res = interpret(func, ())
     assert res == 1214
 
-
+def test_dict_contains():
+    def func():
+        dic = {' 4':1000, ' 8':200}
+        return ' 4' in dic and ' 9' not in dic
+    res = interpret(func, ())
+    assert res is True



More information about the Pypy-commit mailing list