[pypy-svn] r43276 - in pypy/branch/pypy-string-formatting/rpython: . test
arigo at codespeak.net
arigo at codespeak.net
Sat May 12 12:29:35 CEST 2007
Author: arigo
Date: Sat May 12 12:29:35 2007
New Revision: 43276
Modified:
pypy/branch/pypy-string-formatting/rpython/rlist.py
pypy/branch/pypy-string-formatting/rpython/test/test_rlist.py
Log:
Support for "lst += string" in RPython. The idea is to special-case and
support efficiently a few combined operations too: "lst += string[x:y]"
and "lst += char * length".
Modified: pypy/branch/pypy-string-formatting/rpython/rlist.py
==============================================================================
--- pypy/branch/pypy-string-formatting/rpython/rlist.py (original)
+++ pypy/branch/pypy-string-formatting/rpython/rlist.py Sat May 12 12:29:35 2007
@@ -4,6 +4,7 @@
from pypy.rpython.error import TyperError
from pypy.rpython.rmodel import Repr, IteratorRepr, IntegerRepr, inputconst
from pypy.rpython.rslice import AbstractSliceRepr
+from pypy.rpython.rstr import AbstractStringRepr
from pypy.rpython.lltypesystem.lltype import typeOf, Ptr, Void, Signed, Bool
from pypy.rpython.lltypesystem.lltype import nullptr, Char, UniChar
from pypy.rpython import robject
@@ -350,6 +351,17 @@
hop.gendirectcall(ll_extend, v_lst1, v_lst2)
return v_lst1
+class __extend__(pairtype(AbstractListRepr, AbstractStringRepr)):
+
+ def rtype_inplace_add((r_lst1, r_str2), hop):
+ string_repr = r_lst1.rtyper.type_system.rstr.string_repr
+ v_lst1, v_str2 = hop.inputargs(r_lst1, string_repr)
+ c_strlen = hop.inputconst(Void, string_repr.ll.ll_strlen)
+ c_stritem = hop.inputconst(Void, string_repr.ll.ll_stritem_nonneg)
+ hop.gendirectcall(ll_extend_with_str, v_lst1, v_str2,
+ c_strlen, c_stritem)
+ return v_lst1
+
class __extend__(pairtype(AbstractBaseListRepr, AbstractSliceRepr)):
@@ -692,6 +704,18 @@
i += 1
j += 1
+def ll_extend_with_str(lst, s, getstrlen, getstritem):
+ len1 = lst.ll_length()
+ len2 = getstrlen(s)
+ newlength = len1 + len2
+ lst._ll_resize_ge(newlength)
+ i = 0
+ j = len1
+ while i < len2:
+ lst.ll_setitem_fast(j, getstritem(s, i))
+ i += 1
+ j += 1
+
def ll_listslice_startonly(RESLIST, l1, start):
len1 = l1.ll_length()
debug_assert(start >= 0, "unexpectedly negative list slice start")
Modified: pypy/branch/pypy-string-formatting/rpython/test/test_rlist.py
==============================================================================
--- pypy/branch/pypy-string-formatting/rpython/test/test_rlist.py (original)
+++ pypy/branch/pypy-string-formatting/rpython/test/test_rlist.py Sat May 12 12:29:35 2007
@@ -1171,6 +1171,15 @@
else:
assert False
+ def test_charlist_extensions(self):
+ def f(n):
+ s = 'hello%d' % n
+ l = ['a', 'b']
+ l += s
+ return ''.join(l)
+ res = self.interpret(f, [58])
+ assert self.ll_to_string(res) == 'abhello58'
+
class TestLLtype(BaseTestRlist, LLRtypeMixin):
rlist = ll_rlist
More information about the pypy-svn
mailing list