[pypy-commit] pypy rdict-experiments-3: Test and a fix and tweak a heuristic
fijal
noreply at buildbot.pypy.org
Fri Oct 25 23:23:19 CEST 2013
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: rdict-experiments-3
Changeset: r67617:78295af62ea0
Date: 2013-10-25 23:22 +0200
http://bitbucket.org/pypy/pypy/changeset/78295af62ea0/
Log: Test and a fix and tweak a heuristic
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
@@ -611,7 +611,8 @@
@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
@@ -639,7 +640,7 @@
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]
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
@@ -136,10 +136,10 @@
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()
@@ -272,6 +272,22 @@
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}
More information about the pypy-commit
mailing list