Commits

Maciej Fijalkowski committed 78295af

Test and a fix and tweak a heuristic

Comments (0)

Files changed (2)

rpython/rtyper/lltypesystem/rdict.py

 
 @jit.dont_look_inside
 def ll_dict_grow(d):
-    if d.num_items < d.num_used_items // 2:
+    # don't reindex the dict if it's tiny
+    if d.num_items < d.num_used_items // 2 and d.num_items >= 32:
         ll_dict_remove_deleted_items(d)
         return True
 
     ENTRY = lltype.typeOf(d).TO.entries.TO.OF
     isrc = 0
     idst = 0
-    while isrc < len(d.entries):
+    while isrc < d.num_used_items:
         if d.entries.valid(isrc):
             src = d.entries[isrc]
             dst = newitems[idst]

rpython/rtyper/test/test_rdict.py

         DICT = self._get_str_dict()
         ll_d = rdict.ll_newdict(DICT)
         lls = llstr("a")
-        for i in range(20):
+        for i in range(40):
             rdict.ll_dict_setitem(ll_d, lls, i)
             rdict.ll_dict_delitem(ll_d, lls)
-        assert ll_d.num_used_items <= 4
+        assert ll_d.num_used_items <= 10
 
     def test_dict_iteration(self):
         DICT = self._get_str_dict()
 
 class TestRdict(BaseRtypingTest):
 
+    def test_bug(self):
+        keys = [str(i) for i in range(0, 100, 2)]
+
+        def f():
+            d = {}
+            for key in keys:
+                d[key] = 0
+            for i in range(4):
+                print i
+                d['0'] = 13
+                for j in range(len(keys) - 1):
+                    del d[keys[j]]
+                    d[keys[j + 1]] = 42
+
+        self.interpret(f, [])
+
     def test_dict_creation(self):
         def createdict(i):
             d = {'hello' : i}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.