[pypy-commit] pypy fix-bytearray-complexity: All bytearray tests pass again

waedt noreply at buildbot.pypy.org
Mon Jun 2 19:47:08 CEST 2014


Author: Tyler Wade <wayedt at gmail.com>
Branch: fix-bytearray-complexity
Changeset: r71876:38541e58dc34
Date: 2014-05-26 15:14 -0500
http://bitbucket.org/pypy/pypy/changeset/38541e58dc34/

Log:	All bytearray tests pass again

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
@@ -3,7 +3,7 @@
 from rpython.rlib.objectmodel import (
     import_from_mixin, newlist_hint, resizelist_hint, specialize)
 from rpython.rlib.buffer import Buffer
-from rpython.rlib.rstring import StringBuilder
+from rpython.rlib.rstring import StringBuilder, ByteListBuilder
 
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.error import OperationError, oefmt
@@ -86,7 +86,7 @@
 
     @staticmethod
     def _builder(size=100):
-        return BytearrayBuilder(size)
+        return ByteListBuilder(size)
 
     def _newlist_unwrapped(self, space, res):
         return space.newlist([W_BytearrayObject(_make_data(i)) for i in res])
@@ -505,24 +505,6 @@
     def descr_reverse(self, space):
         self.data.reverse()
 
-class BytearrayBuilder(object):
-    def __init__(self, size):
-        self.data = newlist_hint(size)
-
-    def append(self, s):
-        for i in range(len(s)):
-            self.data.append(s[i])
-
-    def append_multiple_char(self, c, count):
-        self.data.extend([c] * count)
-
-    def append_slice(self, value, start, end):
-        for i in range(start, end):
-            self.data.append(value[i])
-
-    def build(self):
-        return self.data
-
 
 
 # ____________________________________________________________
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
@@ -157,7 +157,10 @@
             _get_encoding_and_errors, decode_object, unicode_from_string)
         encoding, errors = _get_encoding_and_errors(space, w_encoding,
                                                     w_errors)
-        if encoding is None and errors is None:
+
+        from pypy.objspace.std.bytearrayobject import W_BytearrayObject
+        if (encoding is None and errors is None and
+            not isinstance(self, W_BytearrayObject)):
             return unicode_from_string(space, self)
         return decode_object(space, self, encoding, errors)
 
diff --git a/pypy/objspace/std/test/test_bytearrayobject.py b/pypy/objspace/std/test/test_bytearrayobject.py
--- a/pypy/objspace/std/test/test_bytearrayobject.py
+++ b/pypy/objspace/std/test/test_bytearrayobject.py
@@ -442,7 +442,7 @@
         u = b.decode('utf-8')
         assert isinstance(u, unicode)
         assert u == u'abcdefghi'
-        assert b.decode()
+        assert b.decode().encode() == b
 
     def test_int(self):
         assert int(bytearray('-1234')) == -1234


More information about the pypy-commit mailing list