[pypy-svn] r13222 - in pypy/dist/pypy/rpython: . test
arigo at codespeak.net
arigo at codespeak.net
Thu Jun 9 11:05:50 CEST 2005
Author: arigo
Date: Thu Jun 9 11:05:48 2005
New Revision: 13222
Modified:
pypy/dist/pypy/rpython/rlist.py
pypy/dist/pypy/rpython/test/test_rlist.py
Log:
list.delslice.
Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py (original)
+++ pypy/dist/pypy/rpython/rlist.py Thu Jun 9 11:05:48 2005
@@ -107,6 +107,17 @@
return hop.gendirectcall(ll_listslice, v_lst, v_slice)
raise TyperError(r_slic)
+ def rtype_delitem((r_lst, r_slic), hop):
+ if r_slic == startonly_slice_repr:
+ v_lst, v_start = hop.inputargs(r_lst, startonly_slice_repr)
+ hop.gendirectcall(ll_listdelslice_startonly, v_lst, v_start)
+ return
+ if r_slic == startstop_slice_repr:
+ v_lst, v_slice = hop.inputargs(r_lst, startstop_slice_repr)
+ hop.gendirectcall(ll_listdelslice, v_lst, v_slice)
+ return
+ raise TyperError(r_slic)
+
class __extend__(pairtype(ListRepr, ListRepr)):
def convert_from_to((r_lst1, r_lst2), v, llops):
if r_lst1.listitem is None or r_lst2.listitem is None:
@@ -242,6 +253,29 @@
l.items = newitems
return l
+def ll_listdelslice_startonly(l1, start):
+ newitems = malloc(typeOf(l1).TO.items.TO, start)
+ j = 0
+ while j < start:
+ newitems[j].item = l1.items[j].item
+ j += 1
+ l1.items = newitems
+
+def ll_listdelslice(l1, slice):
+ start = slice.start
+ stop = slice.stop
+ newlength = len(l1.items) - (stop-start)
+ newitems = malloc(typeOf(l1).TO.items.TO, newlength)
+ j = 0
+ while j < start:
+ newitems[j].item = l1.items[j].item
+ j += 1
+ while j < newlength:
+ newitems[j].item = l1.items[stop].item
+ stop += 1
+ j += 1
+ l1.items = newitems
+
# ____________________________________________________________
#
# Irregular operations.
Modified: pypy/dist/pypy/rpython/test/test_rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rlist.py (original)
+++ pypy/dist/pypy/rpython/test/test_rlist.py Thu Jun 9 11:05:48 2005
@@ -65,6 +65,21 @@
s = ll_newslice(start, stop)
check_list(ll_listslice(l, s), [42, 43, 44, 45][start:stop])
+def test_rlist_delslice():
+ l = sample_list()
+ ll_listdelslice_startonly(l, 3)
+ check_list(l, [42, 43, 44])
+ ll_listdelslice_startonly(l, 0)
+ check_list(l, [])
+ for start in range(5):
+ for stop in range(start, 5):
+ l = sample_list()
+ s = ll_newslice(start, stop)
+ ll_listdelslice(l, s)
+ expected = [42, 43, 44, 45]
+ del expected[start:stop]
+ check_list(l, expected)
+
# ____________________________________________________________
def rtype(fn, argtypes=[]):
@@ -134,4 +149,5 @@
l[-1] = 66
del l[0]
del l[-1]
+ del l[:]
rtype(dummyfn)
More information about the Pypy-commit
mailing list