[pypy-commit] pypy fix-bytearray-complexity: Don't use buffers as the 2nd paramter to rstring.(r)split
waedt
noreply at buildbot.pypy.org
Mon Jun 9 17:17:46 CEST 2014
Author: Tyler Wade <wayedt at gmail.com>
Branch: fix-bytearray-complexity
Changeset: r72003:b2b630192e51
Date: 2014-06-09 09:25 -0500
http://bitbucket.org/pypy/pypy/changeset/b2b630192e51/
Log: Don't use buffers as the 2nd paramter to rstring.(r)split
diff --git a/pypy/objspace/std/stringmethods.py b/pypy/objspace/std/stringmethods.py
--- a/pypy/objspace/std/stringmethods.py
+++ b/pypy/objspace/std/stringmethods.py
@@ -561,16 +561,10 @@
res = split(value, maxsplit=maxsplit)
return self._newlist_unwrapped(space, res)
- if self._use_rstr_ops(space, w_sep):
- by = self._op_val(space, w_sep)
- if len(by) == 0:
- raise oefmt(space.w_ValueError, "empty separator")
- res = split(value, by, maxsplit)
- else:
- by = _get_buffer(space, w_sep)
- if len(by) == 0:
- raise oefmt(space.w_ValueError, "empty separator")
- res = split(value, by, maxsplit)
+ by = self._op_val(space, w_sep)
+ if len(by) == 0:
+ raise oefmt(space.w_ValueError, "empty separator")
+ res = split(value, by, maxsplit)
return self._newlist_unwrapped(space, res)
@@ -582,16 +576,10 @@
res = rsplit(value, maxsplit=maxsplit)
return self._newlist_unwrapped(space, res)
- if self._use_rstr_ops(space, w_sep):
- by = self._op_val(space, w_sep)
- if len(by) == 0:
- raise oefmt(space.w_ValueError, "empty separator")
- res = rsplit(value, by, maxsplit)
- else:
- by = _get_buffer(space, w_sep)
- if len(by) == 0:
- raise oefmt(space.w_ValueError, "empty separator")
- res = rsplit(value, by, maxsplit)
+ by = self._op_val(space, w_sep)
+ if len(by) == 0:
+ raise oefmt(space.w_ValueError, "empty separator")
+ res = rsplit(value, by, maxsplit)
return self._newlist_unwrapped(space, res)
@@ -629,10 +617,7 @@
end))
def _startswith(self, space, value, w_prefix, start, end):
- if self._use_rstr_ops(space, w_prefix):
- return startswith(value, self._op_val(space, w_prefix), start, end)
- else:
- return startswith(value, _get_buffer(space, w_prefix), start, end)
+ return startswith(value, self._op_val(space, w_prefix), start, end)
def descr_endswith(self, space, w_suffix, w_start=None, w_end=None):
(value, start, end) = self._convert_idx_params(space, w_start, w_end,
@@ -646,10 +631,7 @@
end))
def _endswith(self, space, value, w_prefix, start, end):
- if self._use_rstr_ops(space, w_prefix):
- return endswith(value, self._op_val(space, w_prefix), start, end)
- else:
- return endswith(value, _get_buffer(space, w_prefix), start, end)
+ return endswith(value, self._op_val(space, w_prefix), start, end)
def _strip(self, space, w_chars, left, right):
"internal function called by str_xstrip methods"
diff --git a/rpython/rlib/rstring.py b/rpython/rlib/rstring.py
--- a/rpython/rlib/rstring.py
+++ b/rpython/rlib/rstring.py
@@ -56,6 +56,13 @@
i = j + 1
return res
+ if isinstance(value, unicode):
+ assert isinstance(by, unicode)
+ if isinstance(value, str):
+ assert isinstance(by, str)
+ if isinstance(value, list):
+ assert isinstance(by, str)
+
bylen = len(by)
if bylen == 0:
raise ValueError("empty separator")
@@ -131,6 +138,13 @@
res.reverse()
return res
+ if isinstance(value, unicode):
+ assert isinstance(by, unicode)
+ if isinstance(value, str):
+ assert isinstance(by, str)
+ if isinstance(value, list):
+ assert isinstance(by, str)
+
if maxsplit > 0:
res = newlist_hint(min(maxsplit + 1, len(value)))
else:
diff --git a/rpython/rlib/test/test_rstring.py b/rpython/rlib/test/test_rstring.py
--- a/rpython/rlib/test/test_rstring.py
+++ b/rpython/rlib/test/test_rstring.py
@@ -10,14 +10,11 @@
def check_split(value, sub, *args, **kwargs):
result = kwargs['res']
assert split(value, sub, *args) == result
- assert split(value, buffer(sub), *args) == result
list_result = [list(i) for i in result]
assert split(list(value), sub, *args) == list_result
- assert split(list(value), buffer(sub), *args) == list_result
assert split(buffer(value), sub, *args) == result
- assert split(buffer(value), buffer(sub), *args) == result
check_split("", 'x', res=[''])
check_split("a", "a", 1, res=['', ''])
@@ -50,14 +47,11 @@
def check_rsplit(value, sub, *args, **kwargs):
result = kwargs['res']
assert rsplit(value, sub, *args) == result
- assert rsplit(value, buffer(sub), *args) == result
list_result = [list(i) for i in result]
assert rsplit(list(value), sub, *args) == list_result
- assert rsplit(list(value), buffer(sub), *args) == list_result
assert rsplit(buffer(value), sub, *args) == result
- assert rsplit(buffer(value), buffer(sub), *args) == result
check_rsplit("a", "a", 1, res=['', ''])
check_rsplit(" ", " ", 1, res=['', ''])
@@ -87,10 +81,8 @@
def check_replace(value, sub, *args, **kwargs):
result = kwargs['res']
assert replace(value, sub, *args) == result
- assert replace(value, buffer(sub), *args) == result
assert replace(list(value), sub, *args) == list(result)
- assert replace(list(value), buffer(sub), *args) == list(result)
check_replace('one!two!three!', '!', '@', 1, res='one at two!three!')
check_replace('one!two!three!', '!', '', res='onetwothree')
@@ -256,9 +248,6 @@
def test_buffer_parameter(self):
def fn():
res = True
- res = res and split('a//b//c//d', StringBuffer('//')) == ['a', 'b', 'c', 'd']
- res = res and split(u'a//b//c//d', StringBuffer('//')) == [u'a', u'b', u'c', u'd']
- res = res and rsplit('a//b//c//d', StringBuffer('//')) == ['a', 'b', 'c', 'd']
res = res and find('a//b//c//d', StringBuffer('//'), 0, 10) != -1
res = res and rfind('a//b//c//d', StringBuffer('//'), 0, 10) != -1
res = res and count('a//b//c//d', StringBuffer('//'), 0, 10) != 0
More information about the pypy-commit
mailing list