[pypy-svn] r13754 - in pypy/dist/pypy/rpython: . test
hpk at codespeak.net
hpk at codespeak.net
Thu Jun 23 22:08:56 CEST 2005
Author: hpk
Date: Thu Jun 23 22:08:55 2005
New Revision: 13754
Modified:
pypy/dist/pypy/rpython/rdict.py
pypy/dist/pypy/rpython/test/test_rdict.py
Log:
use STRDICT_INITSIZE instead of the 8 literal
Modified: pypy/dist/pypy/rpython/rdict.py
==============================================================================
--- pypy/dist/pypy/rpython/rdict.py (original)
+++ pypy/dist/pypy/rpython/rdict.py Thu Jun 23 22:08:55 2005
@@ -158,8 +158,11 @@
if not entry.key or entry.key == deleted_entry_marker:
raise KeyError
entry.key = deleted_entry_marker
- d.num_items -= 1
# XXX: entry.value = ???
+ d.num_items -= 1
+ num_entries = len(d.entries)
+ if num_entries > STRDICT_INITSIZE and d.num_items < num_entries / 4:
+ ll_strdict_resize(d)
def ll_strdict_resize(d):
old_entries = d.entries
@@ -167,7 +170,7 @@
# make a 'new_size' estimate and shrink it if there are many
# deleted entry markers
new_size = old_size * 2
- while new_size >= 8 and d.num_items < new_size / 4:
+ while new_size > STRDICT_INITSIZE and d.num_items < new_size / 4:
new_size /= 2
d.entries = lltype.malloc(lltype.typeOf(old_entries).TO, new_size)
d.num_pristine_entries = new_size - d.num_items
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 Thu Jun 23 22:08:55 2005
@@ -78,7 +78,7 @@
return d[c2]
char_by_hash = {}
- base = 8
+ base = rdict.STRDICT_INITSIZE
for y in range(0, 256):
y = chr(y)
y_hash = lowlevelhash(y) % base
@@ -115,7 +115,10 @@
c7 = chr(c7) ; d[c7] = 1; del d[c7]
return d
- res = interpret(func3, [ord(char_by_hash[i][0]) for i in range(8)])
+ if rdict.STRDICT_INITSIZE != 8:
+ py.test.skip("make dict tests more indepdent from initsize")
+ res = interpret(func3, [ord(char_by_hash[i][0])
+ for i in range(rdict.STRDICT_INITSIZE)])
count_frees = 0
for i in range(len(res.entries)):
if not res.entries[i].key:
@@ -125,8 +128,8 @@
def test_dict_resize():
def func():
d = {}
- for i in range(8):
+ for i in range(rdict.STRDICT_INITSIZE):
d[chr(ord('a') + i)] = i
return d
res = interpret(func, [])
- assert len(res.entries) > 8
+ assert len(res.entries) > rdict.STRDICT_INITSIZE
More information about the Pypy-commit
mailing list