Author: Armin Rigo <[email protected]>
Branch: rdict-experiments-3
Changeset: r67290:25503fc2783e
Date: 2013-10-10 16:23 +0200
http://bitbucket.org/pypy/pypy/changeset/25503fc2783e/

Log:    general progressiness

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
@@ -292,7 +292,7 @@
     def rtype_method_update(self, hop):
         v_dic1, v_dic2 = hop.inputargs(self, self)
         hop.exception_cannot_occur()
-        return hop.gendirectcall(ll_update, v_dic1, v_dic2)
+        return hop.gendirectcall(ll_dict_update, v_dic1, v_dic2)
 
     def _rtype_method_kvi(self, hop, ll_func):
         v_dic, = hop.inputargs(self)
@@ -957,7 +957,7 @@
 
 def ll_dict_setdefault(dict, key, default):
     hash = dict.keyhash(key)
-    index = dict.lookup_function(dict, key, dict.keyhash(key), FLAG_STORE)
+    index = dict.lookup_function(dict, key, hash, FLAG_STORE)
     if index == -1:
         _ll_dict_setitem_lookup_done(dict, key, default, hash, -1)
         return default
@@ -1006,19 +1006,19 @@
     # old_entries.delete() XXX
 ll_dict_clear.oopspec = 'dict.clear(d)'
 
-def ll_update(dic1, dic2):
-    entries = dic2.entries
-    d2len = len(entries)
+def ll_dict_update(dic1, dic2):
     i = 0
-    while i < d2len:
+    while i < dic2.num_used_items:
+        entries = dic2.entries
         if entries.valid(i):
             entry = entries[i]
             hash = entries.hash(i)
             key = entry.key
-            j = ll_dict_lookup(dic1, key, hash)
-            _ll_dict_setitem_lookup_done(dic1, key, entry.value, hash, j)
+            value = entry.value
+            index = dic1.lookup_function(dic1, key, hash, FLAG_STORE)
+            _ll_dict_setitem_lookup_done(dic1, key, value, hash, index)
         i += 1
-ll_update.oopspec = 'dict.update(dic1, dic2)'
+ll_dict_update.oopspec = 'dict.update(dic1, dic2)'
 
 # this is an implementation of keys(), values() and items()
 # in a single function.
@@ -1081,7 +1081,7 @@
         i -= 1
 
     key = entries[i].key
-    index = dic.lookup_function(dic, key, dic.keyhash(key),
+    index = dic.lookup_function(dic, key, entries.hash(i),
                                 FLAG_DELETE_TRY_HARD)
     # if the lookup function returned me a random strange thing,
     # don't care about deleting the item
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
@@ -229,6 +229,18 @@
             assert rdict.ll_dict_get(ll_d3, llstr("j"), 42) == 2
             assert rdict.ll_dict_get(ll_d3, llstr("i"), 42) == 42
 
+    def test_update(self):
+        DICT = self._get_str_dict()
+        ll_d1 = rdict.ll_newdict(DICT)
+        ll_d2 = rdict.ll_newdict(DICT)
+        rdict.ll_dict_setitem(ll_d1, llstr("k"), 5)
+        rdict.ll_dict_setitem(ll_d1, llstr("j"), 6)
+        rdict.ll_dict_setitem(ll_d2, llstr("i"), 7)
+        rdict.ll_dict_setitem(ll_d2, llstr("k"), 8)
+        rdict.ll_dict_update(ll_d1, ll_d2)
+        for key, value in [("k", 8), ("i", 7), ("j", 6)]:
+            assert rdict.ll_dict_getitem(ll_d1, llstr(key)) == value
+
 class TestRDictDirectDummyKey(TestRDictDirect):
     class dummykeyobj:
         ll_dummy_value = llstr("dupa")
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to