Author: Alex Gaynor <[email protected]>
Branch: kill-single-impl-multimethods
Changeset: r46356:e85a2774b88d
Date: 2011-08-07 15:33 -0700
http://bitbucket.org/pypy/pypy/changeset/e85a2774b88d/
Log: {i,r,}mul aren't specialized on receiver, kill multimethod.
diff --git a/pypy/objspace/std/bytearraytype.py
b/pypy/objspace/std/bytearraytype.py
--- a/pypy/objspace/std/bytearraytype.py
+++ b/pypy/objspace/std/bytearraytype.py
@@ -138,6 +138,28 @@
def descr__buffer__(self, space):
return space.wrap(BytearrayBuffer(self.data))
+ def descr__mul__(self, space, w_times):
+ try:
+ times = space.getindex_w(w_times, space.w_OverflowError)
+ except OperationError, e:
+ if e.match(space, space.w_TypeError):
+ return space.w_NotImplemented
+ raise
+ return W_BytearrayObject(self.data * times)
+
+ def descr__rmul__(self, space, w_times):
+ return self.descr__mul__(space, w_times)
+
+ def descr__imul__(self, space, w_times):
+ try:
+ times = space.getindex_w(w_times, space.w_OverflowError)
+ except OperationError, e:
+ if e.match(space, space.w_TypeError):
+ return space.w_NotImplemented
+ raise
+ self.data *= times
+ return self
+
@gateway.unwrap_spec(idx=int)
def descr_insert(self, space, idx, w_other):
"""B.insert(index, int) -> None
@@ -209,8 +231,6 @@
Reverse the order of the values in B in place."""
self.data.reverse()
-
-
class BytearrayBuffer(RWBuffer):
def __init__(self, data):
self.data = data
@@ -410,32 +430,6 @@
w_bytearray1.data += w_bytearray2.data
return w_bytearray1
-def mul_bytearray_times(space, w_bytearray, w_times):
- try:
- times = space.getindex_w(w_times, space.w_OverflowError)
- except OperationError, e:
- if e.match(space, space.w_TypeError):
- raise FailedToImplement
- raise
- data = w_bytearray.data
- return W_BytearrayObject(data * times)
-
-def mul__Bytearray_ANY(space, w_bytearray, w_times):
- return mul_bytearray_times(space, w_bytearray, w_times)
-
-def mul__ANY_Bytearray(space, w_times, w_bytearray):
- return mul_bytearray_times(space, w_bytearray, w_times)
-
-def inplace_mul__Bytearray_ANY(space, w_bytearray, w_times):
- try:
- times = space.getindex_w(w_times, space.w_OverflowError)
- except OperationError, e:
- if e.match(space, space.w_TypeError):
- raise FailedToImplement
- raise
- w_bytearray.data *= times
- return w_bytearray
-
def contains__Bytearray_ANY(space, w_bytearray, w_sub):
# XXX slow - copies, needs rewriting
w_str = space.wrap(space.bufferstr_new_w(w_sub))
@@ -748,6 +742,9 @@
__init__ = gateway.interp2app(W_BytearrayObject.descr__init__),
__len__ = gateway.interp2app(W_BytearrayObject.descr__len__),
+ __mul__ = gateway.interp2app(W_BytearrayObject.descr__mul__),
+ __rmul__ = gateway.interp2app(W_BytearrayObject.descr__rmul__),
+ __imul__ = gateway.interp2app(W_BytearrayObject.descr__imul__),
__reduce__ = gateway.interp2app(W_BytearrayObject.descr__reduce__),
__buffer__ = gateway.interp2app(W_BytearrayObject.descr__buffer__),
__str__ = gateway.interp2app(W_BytearrayObject.descr__str__),
diff --git a/pypy/objspace/std/test/test_bytes.py
b/pypy/objspace/std/test/test_bytes.py
--- a/pypy/objspace/std/test/test_bytes.py
+++ b/pypy/objspace/std/test/test_bytes.py
@@ -66,6 +66,7 @@
assert b1 + b2 == bytearray('hello world')
assert b1 * 2 == bytearray('hello hello ')
assert b1 * 1 is not b1
+ assert 2 * b1 == bytearray('hello hello ')
b3 = b1
b3 *= 3
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit