Author: Carl Friedrich Bolz <[email protected]>
Branch:
Changeset: r48750:256f96157565
Date: 2011-11-04 14:08 +0100
http://bitbucket.org/pypy/pypy/changeset/256f96157565/
Log: similarly simplify some unicode code
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
@@ -10,7 +10,7 @@
from pypy.objspace.std import slicetype, newformat
from pypy.objspace.std.tupleobject import W_TupleObject
from pypy.rlib.rarithmetic import intmask, ovfcheck
-from pypy.rlib.objectmodel import compute_hash
+from pypy.rlib.objectmodel import compute_hash, specialize
from pypy.rlib.rstring import UnicodeBuilder
from pypy.rlib.runicode import unicode_encode_unicode_escape
from pypy.module.unicodedata import unicodedb
@@ -475,32 +475,29 @@
index = length
return index
-def _convert_idx_params(space, w_self, w_sub, w_start, w_end,
upper_bound=False):
- assert isinstance(w_sub, W_UnicodeObject)
[email protected](4)
+def _convert_idx_params(space, w_self, w_start, w_end, upper_bound=False):
self = w_self._value
- sub = w_sub._value
start, end = slicetype.unwrap_start_stop(
space, len(self), w_start, w_end, upper_bound)
- return (self, sub, start, end)
-_convert_idx_params._annspecialcase_ = 'specialize:arg(5)'
+ return (self, start, end)
def unicode_endswith__Unicode_Unicode_ANY_ANY(space, w_self, w_substr,
w_start, w_end):
- self, substr, start, end = _convert_idx_params(space, w_self, w_substr,
+ self, start, end = _convert_idx_params(space, w_self,
w_start, w_end, True)
- return space.newbool(stringendswith(self, substr, start, end))
+ return space.newbool(stringendswith(self, w_substr._value, start, end))
def unicode_startswith__Unicode_Unicode_ANY_ANY(space, w_self, w_substr,
w_start, w_end):
- self, substr, start, end = _convert_idx_params(space, w_self, w_substr,
- w_start, w_end, True)
+ self, start, end = _convert_idx_params(space, w_self, w_start, w_end, True)
# XXX this stuff can be waaay better for ootypebased backends if
# we re-use more of our rpython machinery (ie implement startswith
# with additional parameters as rpython)
- return space.newbool(stringstartswith(self, substr, start, end))
+ return space.newbool(stringstartswith(self, w_substr._value, start, end))
def unicode_startswith__Unicode_Tuple_ANY_ANY(space, w_unistr, w_prefixes,
w_start, w_end):
- unistr, _, start, end = _convert_idx_params(space, w_unistr,
space.wrap(u''),
- w_start, w_end, True)
+ unistr, start, end = _convert_idx_params(space, w_unistr,
+ w_start, w_end, True)
for w_prefix in space.fixedview(w_prefixes):
prefix = space.unicode_w(w_prefix)
if stringstartswith(unistr, prefix, start, end):
@@ -509,7 +506,7 @@
def unicode_endswith__Unicode_Tuple_ANY_ANY(space, w_unistr, w_suffixes,
w_start, w_end):
- unistr, _, start, end = _convert_idx_params(space, w_unistr,
space.wrap(u''),
+ unistr, start, end = _convert_idx_params(space, w_unistr,
w_start, w_end, True)
for w_suffix in space.fixedview(w_suffixes):
suffix = space.unicode_w(w_suffix)
@@ -615,37 +612,32 @@
return space.newlist(lines)
def unicode_find__Unicode_Unicode_ANY_ANY(space, w_self, w_substr, w_start,
w_end):
- self, substr, start, end = _convert_idx_params(space, w_self, w_substr,
- w_start, w_end)
- return space.wrap(self.find(substr, start, end))
+ self, start, end = _convert_idx_params(space, w_self, w_start, w_end)
+ return space.wrap(self.find(w_substr._value, start, end))
def unicode_rfind__Unicode_Unicode_ANY_ANY(space, w_self, w_substr, w_start,
w_end):
- self, substr, start, end = _convert_idx_params(space, w_self, w_substr,
- w_start, w_end)
- return space.wrap(self.rfind(substr, start, end))
+ self, start, end = _convert_idx_params(space, w_self, w_start, w_end)
+ return space.wrap(self.rfind(w_substr._value, start, end))
def unicode_index__Unicode_Unicode_ANY_ANY(space, w_self, w_substr, w_start,
w_end):
- self, substr, start, end = _convert_idx_params(space, w_self, w_substr,
- w_start, w_end)
- index = self.find(substr, start, end)
+ self, start, end = _convert_idx_params(space, w_self, w_start, w_end)
+ index = self.find(w_substr._value, start, end)
if index < 0:
raise OperationError(space.w_ValueError,
space.wrap('substring not found'))
return space.wrap(index)
def unicode_rindex__Unicode_Unicode_ANY_ANY(space, w_self, w_substr, w_start,
w_end):
- self, substr, start, end = _convert_idx_params(space, w_self, w_substr,
- w_start, w_end)
- index = self.rfind(substr, start, end)
+ self, start, end = _convert_idx_params(space, w_self, w_start, w_end)
+ index = self.rfind(w_substr._value, start, end)
if index < 0:
raise OperationError(space.w_ValueError,
space.wrap('substring not found'))
return space.wrap(index)
def unicode_count__Unicode_Unicode_ANY_ANY(space, w_self, w_substr, w_start,
w_end):
- self, substr, start, end = _convert_idx_params(space, w_self, w_substr,
- w_start, w_end)
- return space.wrap(self.count(substr, start, end))
+ self, start, end = _convert_idx_params(space, w_self, w_start, w_end)
+ return space.wrap(self.count(w_substr._value, start, end))
def unicode_split__Unicode_None_ANY(space, w_self, w_none, w_maxsplit):
maxsplit = space.int_w(w_maxsplit)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit