[pypy-commit] pypy default: push these specifics out into the individual classes
pjenvey
noreply at buildbot.pypy.org
Sat Jan 25 01:56:00 CET 2014
Author: Philip Jenvey <pjenvey at underboss.org>
Branch:
Changeset: r68925:be9bfeaafbe7
Date: 2014-01-24 16:18 -0800
http://bitbucket.org/pypy/pypy/changeset/be9bfeaafbe7/
Log: push these specifics out into the individual classes
diff --git a/pypy/objspace/std/bytearrayobject.py b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -376,14 +376,36 @@
raise operationerrfmt(space.w_ValueError,
"value not found in bytearray")
+ _StringMethods_descr_contains = descr_contains
+ def descr_contains(self, space, w_sub):
+ if space.isinstance_w(w_sub, space.w_int):
+ char = space.int_w(w_sub)
+ return _descr_contains_bytearray(self.data, space, char)
+ return self._StringMethods_descr_contains(space, w_sub)
+
def descr_reverse(self, space):
self.data.reverse()
+# ____________________________________________________________
+# helpers for slow paths, moved out because they contain loops
+
def _make_data(s):
return [s[i] for i in range(len(s))]
+def _descr_contains_bytearray(data, space, char):
+ if not 0 <= char < 256:
+ raise operationerrfmt(space.w_ValueError,
+ "byte must be in range(0, 256)")
+ for c in data:
+ if ord(c) == char:
+ return space.w_True
+ return space.w_False
+
+# ____________________________________________________________
+
+
def getbytevalue(space, w_value):
if space.isinstance_w(w_value, space.w_str):
string = space.str_w(w_value)
diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py
--- a/pypy/objspace/std/bytesobject.py
+++ b/pypy/objspace/std/bytesobject.py
@@ -703,11 +703,14 @@
return self_as_uni._new(res)
return self._StringMethods_descr_replace(space, w_old, w_new, count)
- def descr_lower(self, space):
- return W_BytesObject(self._value.lower())
-
- def descr_upper(self, space):
- return W_BytesObject(self._value.upper())
+ _StringMethods_descr_join = descr_join
+ def descr_join(self, space, w_list):
+ l = space.listview_bytes(w_list)
+ if l is not None:
+ if len(l) == 1:
+ return space.wrap(l[0])
+ return space.wrap(self._val(space).join(l))
+ return self._StringMethods_descr_join(space, w_list)
def _join_return_one(self, space, w_obj):
return (space.is_w(space.type(w_obj), space.w_str) or
@@ -727,6 +730,12 @@
w_u = space.call_function(space.w_unicode, self)
return space.call_method(w_u, "join", w_list)
+ def descr_lower(self, space):
+ return W_BytesObject(self._value.lower())
+
+ def descr_upper(self, space):
+ return W_BytesObject(self._value.upper())
+
def descr_formatter_parser(self, space):
from pypy.objspace.std.newformat import str_template_formatter
tformat = str_template_formatter(space, space.str_w(self))
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
@@ -35,11 +35,6 @@
# pass
def descr_contains(self, space, w_sub):
- from pypy.objspace.std.bytearrayobject import W_BytearrayObject
- if (isinstance(self, W_BytearrayObject) and
- space.isinstance_w(w_sub, space.w_int)):
- char = space.int_w(w_sub)
- return _descr_contains_bytearray(self.data, space, char)
value = self._val(space)
other = self._op_val(space, w_sub)
return space.newbool(value.find(other) >= 0)
@@ -317,22 +312,6 @@
return space.newbool(cased)
def descr_join(self, space, w_list):
- from pypy.objspace.std.bytesobject import W_BytesObject
- from pypy.objspace.std.unicodeobject import W_UnicodeObject
-
- if isinstance(self, W_BytesObject):
- l = space.listview_bytes(w_list)
- if l is not None:
- if len(l) == 1:
- return space.wrap(l[0])
- return space.wrap(self._val(space).join(l))
- elif isinstance(self, W_UnicodeObject):
- l = space.listview_unicode(w_list)
- if l is not None:
- if len(l) == 1:
- return space.wrap(l[0])
- return space.wrap(self._val(space).join(l))
-
list_w = space.listview(w_list)
size = len(list_w)
@@ -689,16 +668,6 @@
# ____________________________________________________________
# helpers for slow paths, moved out because they contain loops
-def _descr_contains_bytearray(data, space, char):
- if not 0 <= char < 256:
- raise operationerrfmt(space.w_ValueError,
- "byte must be in range(0, 256)")
- for c in data:
- if ord(c) == char:
- return space.w_True
- return space.w_False
-
-
@specialize.argtype(0)
def _descr_getslice_slowpath(selfvalue, start, step, sl):
return [selfvalue[start + i*step] for i in range(sl)]
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
@@ -317,6 +317,15 @@
w_errors)
return encode_object(space, self, encoding, errors)
+ _StringMethods_descr_join = descr_join
+ def descr_join(self, space, w_list):
+ l = space.listview_unicode(w_list)
+ if l is not None:
+ if len(l) == 1:
+ return space.wrap(l[0])
+ return space.wrap(self._val(space).join(l))
+ return self._StringMethods_descr_join(space, w_list)
+
def _join_return_one(self, space, w_obj):
return space.is_w(space.type(w_obj), space.w_unicode)
More information about the pypy-commit
mailing list