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

fijal noreply at buildbot.pypy.org
Thu Oct 10 14:44:07 CEST 2013


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: rdict-experiments-3
Changeset: r67284:575b3b774200
Date: 2013-10-10 12:08 +0200
http://bitbucket.org/pypy/pypy/changeset/575b3b774200/

Log:	(fijal, arigo) clear

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
@@ -328,7 +328,7 @@
     def rtype_method_clear(self, hop):
         v_dict, = hop.inputargs(self)
         hop.exception_cannot_occur()
-        return hop.gendirectcall(ll_clear, v_dict)
+        return hop.gendirectcall(ll_dict_clear, v_dict)
 
     def rtype_method_popitem(self, hop):
         v_dict, = hop.inputargs(self)
@@ -1007,16 +1007,18 @@
     return d
 ll_copy.oopspec = 'dict.copy(dict)'
 
-def ll_clear(d):
-    if (len(d.entries) == DICT_INITSIZE and
-        d.resize_counter == DICT_INITSIZE * 2):
+def ll_dict_clear(d):
+    if d.num_used_items == 0:
         return
+    DICT = lltype.typeOf(d).TO
     old_entries = d.entries
-    d.entries = lltype.typeOf(old_entries).TO.allocate(DICT_INITSIZE)
+    d.entries = DICT.lookup_family.empty_array
+    ll_malloc_indexes_and_choose_lookup(d, DICT_INITSIZE)
     d.num_items = 0
+    d.num_used_items = 0
     d.resize_counter = DICT_INITSIZE * 2
-    old_entries.delete()
-ll_clear.oopspec = 'dict.clear(d)'
+    # old_entries.delete() XXX
+ll_dict_clear.oopspec = 'dict.clear(d)'
 
 def ll_update(dic1, dic2):
     entries = dic2.entries
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
@@ -184,6 +184,15 @@
         assert rdict.ll_dict_contains(ll_d, llstr("k"))
         assert not rdict.ll_dict_contains(ll_d, llstr("j"))
 
+    def test_clear(self):
+        DICT = self._get_str_dict()
+        ll_d = rdict.ll_newdict(DICT)
+        rdict.ll_dict_setitem(ll_d, llstr("k"), 1)
+        rdict.ll_dict_setitem(ll_d, llstr("j"), 1)
+        rdict.ll_dict_setitem(ll_d, llstr("l"), 1)
+        rdict.ll_dict_clear(ll_d)
+        assert ll_d.num_items == 0
+
 class TestRDictDirectDummyKey(TestRDictDirect):
     class dummykeyobj:
         ll_dummy_value = llstr("dupa")


More information about the pypy-commit mailing list