[pypy-dev] Re: [pypy-svn] r13221 - in pypy/dist/pypy/rpython: . test

Ben.Young at risk.sungard.com Ben.Young at risk.sungard.com
Thu Jun 9 11:08:46 CEST 2005


Hi Arigo,

Looking at these commits, I just have a quick question. Can the ll_ 
functions call each other? If they could then all the ll_delitem functions 
could just delagate to the noneg versions. Also, does the bounds checking 
happen at this level, or at a lower one.

In a week or so I may have a little time to do a bit of coding. Is there 
anything specific I should look at? For instance I noticed that at the 
moment the list rep resizes exactly. The python version (and stuff like 
std::vector in c++) have a overallocation stratagy thay minimises 
allocation calls. Would this be an idea I could try to implement in 
rpython?

Cheers,
Ben

pypy-svn-bounces at codespeak.net wrote on 09/06/2005 09:53:32:

> Author: arigo
> Date: Thu Jun  9 10:53:30 2005
> New Revision: 13221
> 
> Modified:
>    pypy/dist/pypy/rpython/rlist.py
>    pypy/dist/pypy/rpython/test/test_rlist.py
> Log:
> list.delitem; tests.
> 
> 
> Modified: pypy/dist/pypy/rpython/rlist.py
> 
==============================================================================
> --- pypy/dist/pypy/rpython/rlist.py   (original)
> +++ pypy/dist/pypy/rpython/rlist.py   Thu Jun  9 10:53:30 2005
> @@ -88,6 +88,14 @@
>              llfn = ll_setitem
>          return hop.gendirectcall(llfn, v_lst, v_index, v_item)
> 
> +    def rtype_delitem((r_lst, r_int), hop):
> +        v_lst, v_index = hop.inputargs(r_lst, Signed)
> +        if hop.args_s[1].nonneg:
> +            llfn = ll_delitem_nonneg
> +        else:
> +            llfn = ll_delitem
> +        return hop.gendirectcall(llfn, v_lst, v_index)
> +
>  class __extend__(pairtype(ListRepr, SliceRepr)):
> 
>      def rtype_getitem((r_lst, r_slic), hop):
> @@ -143,13 +151,39 @@
>          i += len(l.items)
>      return l.items[i].item
> 
> +def ll_setitem_nonneg(l, i, newitem):
> +    l.items[i].item = newitem
> +
>  def ll_setitem(l, i, newitem):
>      if i<0:
>          i += len(l.items)
>      l.items[i].item = newitem
> 
> -def ll_setitem_nonneg(l, i, newitem):
> -    l.items[i].item = newitem
> +def ll_delitem(l, i):
> +    if i < 0:
> +        i += len(l.items)
> +    newlength = len(l.items) - 1
> +    newitems = malloc(typeOf(l).TO.items.TO, newlength)
> +    j = 0
> +    while j < i:
> +        newitems[j].item = l.items[j].item
> +        j += 1
> +    while j < newlength:
> +        newitems[j].item = l.items[j+1].item
> +        j += 1
> +    l.items = newitems
> +
> +def ll_delitem_nonneg(l, i):
> +    newlength = len(l.items) - 1
> +    newitems = malloc(typeOf(l).TO.items.TO, newlength)
> +    j = 0
> +    while j < i:
> +        newitems[j].item = l.items[j].item
> +        j += 1
> +    while j < newlength:
> +        newitems[j].item = l.items[j+1].item
> +        j += 1
> +    l.items = newitems
> 
>  def ll_concat(l1, l2):
>      len1 = len(l1.items)
> 
> 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 10:53:30 2005
> @@ -30,6 +30,21 @@
>      assert ll_len(l) == 4
>      check_list(l, [42, 43, 44, 45])
> 
> +def test_rlist_set_del():
> +    l = sample_list()
> +    ll_setitem(l, -1, 99)
> +    check_list(l, [42, 43, 44, 99])
> +    ll_setitem_nonneg(l, 1, 77)
> +    check_list(l, [42, 77, 44, 99])
> +    ll_delitem_nonneg(l, 0)
> +    check_list(l, [77, 44, 99])
> +    ll_delitem(l, -2)
> +    check_list(l, [77, 99])
> +    ll_delitem(l, 1)
> +    check_list(l, [77])
> +    ll_delitem(l, 0)
> +    check_list(l, [])
> +
>  def test_rlist_extend_concat():
>      l = sample_list()
>      ll_extend(l, l)
> @@ -110,4 +125,13 @@
>      def dummyfn():
>          l = [5, 6, 7, 8, 9]
>          return l[:2], l[1:4], l[3:]
> -    rtype(dummyfn).view()
> +    rtype(dummyfn)
> +
> +def test_set_del_item():
> +    def dummyfn():
> +        l = [5, 6, 7]
> +        l[1] = 55
> +        l[-1] = 66
> +        del l[0]
> +        del l[-1]
> +    rtype(dummyfn)
> _______________________________________________
> pypy-svn mailing list
> pypy-svn at codespeak.net
> http://codespeak.net/mailman/listinfo/pypy-svn
> 




More information about the Pypy-dev mailing list