[pypy-svn] pypy bytearray: (lac, mfoord) in place multiplication of bytearrays
mfoord
commits-noreply at bitbucket.org
Thu Jan 20 19:22:22 CET 2011
Author: Michael Foord <michael at voidspace.org.uk>
Branch: bytearray
Changeset: r41067:8b773b02d082
Date: 2011-01-20 19:21 +0100
http://bitbucket.org/pypy/pypy/changeset/8b773b02d082/
Log: (lac, mfoord) in place multiplication of bytearrays
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
@@ -160,6 +160,16 @@
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 eq__Bytearray_Bytearray(space, w_bytearray1, w_bytearray2):
data1 = w_bytearray1.data
data2 = w_bytearray2.data
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
@@ -67,6 +67,12 @@
assert b1 * 2 == bytearray('hello hello ')
assert b1 * 1 is not b1
+ b3 = b1
+ b3 *= 3
+ assert b3 == 'hello hello hello '
+ assert type(b3) == bytearray
+ assert b3 is b1
+
def test_contains(self):
assert ord('l') in bytearray('hello')
assert 'l' in bytearray('hello')
More information about the Pypy-commit
mailing list