Author: Carl Friedrich Bolz <[email protected]>
Branch:
Changeset: r64906:8a1612cebb3c
Date: 2013-06-13 23:53 +0200
http://bitbucket.org/pypy/pypy/changeset/8a1612cebb3c/
Log: use more newlist_str/unicode
diff --git a/pypy/objspace/std/stringobject.py
b/pypy/objspace/std/stringobject.py
--- a/pypy/objspace/std/stringobject.py
+++ b/pypy/objspace/std/stringobject.py
@@ -325,33 +325,6 @@
res.reverse()
return space.newlist_str(res)
-def make_rsplit_with_delim(funcname, sliced):
- from rpython.tool.sourcetools import func_with_new_name
-
- def fn(space, w_self, w_by, w_maxsplit=-1):
- maxsplit = space.int_w(w_maxsplit)
- value = w_self._value
- end = len(value)
- by = w_by._value
- bylen = len(by)
- if bylen == 0:
- raise OperationError(space.w_ValueError, space.wrap("empty
separator"))
-
- res_w = []
- while maxsplit != 0:
- next = value.rfind(by, 0, end)
- if next < 0:
- break
- res_w.append(sliced(space, value, next+bylen, end, w_self))
- end = next
- maxsplit -= 1 # NB. if it's already < 0, it stays < 0
-
- res_w.append(sliced(space, value, 0, end, w_self))
- res_w.reverse()
- return space.newlist(res_w)
-
- return func_with_new_name(fn, funcname)
-
def str_rsplit__String_String_ANY(space, w_self, w_by, w_maxsplit=-1):
maxsplit = space.int_w(w_maxsplit)
value = w_self._value
@@ -755,7 +728,7 @@
u_keepends = space.int_w(w_keepends) # truth value, but type checked
data = w_self._value
selflen = len(data)
- strs_w = []
+ strs = []
i = j = 0
while i < selflen:
# Find a line and append it
@@ -768,12 +741,12 @@
i += 1
if u_keepends:
eol = i
- strs_w.append(sliced(space, data, j, eol, w_self))
+ strs.append(data[j:eol])
j = i
if j < selflen:
- strs_w.append(sliced(space, data, j, len(data), w_self))
- return space.newlist(strs_w)
+ strs.append(data[j:])
+ return space.newlist_str(strs)
def str_zfill__String_ANY(space, w_self, w_width):
input = w_self._value
diff --git a/pypy/objspace/std/unicodeobject.py
b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -8,8 +8,7 @@
from pypy.objspace.std.multimethod import FailedToImplement
from pypy.objspace.std.noneobject import W_NoneObject
from pypy.objspace.std.sliceobject import W_SliceObject, normalize_simple_slice
-from pypy.objspace.std.stringobject import (
- W_StringObject, make_rsplit_with_delim)
+from pypy.objspace.std.stringobject import W_StringObject
from pypy.objspace.std.stringtype import stringendswith, stringstartswith
from pypy.objspace.std.register_all import register_all
from rpython.rlib import jit
@@ -608,17 +607,17 @@
if (self[pos] == u'\r' and pos + 1 < end and
self[pos + 1] == u'\n'):
# Count CRLF as one linebreak
- lines.append(W_UnicodeObject(self[start:pos + keepends * 2]))
+ lines.append(self[start:pos + keepends * 2])
pos += 1
else:
- lines.append(W_UnicodeObject(self[start:pos + keepends]))
+ lines.append(self[start:pos + keepends])
pos += 1
start = pos
else:
pos += 1
if not unicodedb.islinebreak(ord(self[end - 1])):
- lines.append(W_UnicodeObject(self[start:]))
- return space.newlist(lines)
+ lines.append(self[start:])
+ return space.newlist_unicode(lines)
def unicode_find__Unicode_Unicode_ANY_ANY(space, w_self, w_substr, w_start,
w_end):
self, start, end = _convert_idx_params(space, w_self, w_start, w_end)
@@ -831,7 +830,7 @@
def unicode_expandtabs__Unicode_ANY(space, w_self, w_tabsize):
self = w_self._value
tabsize = space.int_w(w_tabsize)
- parts = self.split(self, u'\t')
+ parts = self.split(u'\t')
result = [parts[0]]
prevsize = 0
for ch in parts[0]:
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit