Author: Maciej Fijalkowski <[email protected]>
Branch: rdict-experiments-3
Changeset: r67245:75f232eda0b4
Date: 2013-10-09 15:58 +0200
http://bitbucket.org/pypy/pypy/changeset/75f232eda0b4/
Log: (fijal, arigo) cover more cases
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
@@ -539,19 +539,19 @@
d.resize_counter -= 3
def ll_dict_delitem(d, key):
- i = ll_dict_lookup(d, key, d.keyhash(key))
- if i & HIGHEST_BIT:
+ index = d.lookup_function(d, key, d.keyhash(key), FLAG_DELETE)
+ if index == -1:
raise KeyError
- _ll_dict_del(d, i)
+ _ll_dict_del(d, index)
@jit.look_inside_iff(lambda d, i: jit.isvirtual(d) and jit.isconstant(i))
-def _ll_dict_del(d, i):
- d.entries.mark_deleted(i)
+def _ll_dict_del(d, index):
+ d.entries.mark_deleted(index)
d.num_items -= 1
# clear the key and the value if they are GC pointers
ENTRIES = lltype.typeOf(d.entries).TO
ENTRY = ENTRIES.OF
- entry = d.entries[i]
+ entry = d.entries[index]
if ENTRIES.must_clear_key:
entry.key = lltype.nullptr(ENTRY.key.TO)
if ENTRIES.must_clear_value:
@@ -624,8 +624,9 @@
if index >= VALID_OFFSET:
checkingkey = entries[index - VALID_OFFSET].key
if direct_compare and checkingkey == key:
- XXX
- return index # found the entry
+ if store_flag == FLAG_DELETE:
+ indexes[i] = rffi.cast(T, DELETED)
+ return index - VALID_OFFSET # found the entry
if d.keyeq is not None and entries.hash(index - VALID_OFFSET) ==
hash:
# correct hash, maybe the key is e.g. a different pointer to
# an equal object
@@ -644,6 +645,8 @@
return ll_dict_lookup(d, key, hash,
ll_index_getitem_int)
if found:
+ if store_flag == FLAG_DELETE:
+ indexes[i] = rffi.cast(T, DELETED)
return index - VALID_OFFSET
freeslot = -1
elif index == DELETED:
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
@@ -47,9 +47,15 @@
def test_dict_creation(self):
DICT = self._get_str_dict()
ll_d = rdict.ll_newdict(DICT)
- rdict.ll_dict_setitem(ll_d, llstr("abc"), 13)
+ lls = llstr("abc")
+ rdict.ll_dict_setitem(ll_d, lls, 13)
assert count_items(ll_d, rdict.FREE) == rdict.DICT_INITSIZE - 1
assert rdict.ll_dict_getitem(ll_d, llstr("abc")) == 13
+ assert rdict.ll_dict_getitem(ll_d, lls) == 13
+ rdict.ll_dict_setitem(ll_d, lls, 42)
+ assert rdict.ll_dict_getitem(ll_d, lls) == 42
+ rdict.ll_dict_setitem(ll_d, llstr("abc"), 43)
+ assert rdict.ll_dict_getitem(ll_d, lls) == 43
def test_dict_del_lastitem(self):
DICT = self._get_str_dict()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit