Author: Armin Rigo <ar...@tunes.org> Branch: py3.6 Changeset: r96897:4effc72e379f Date: 2019-07-01 14:38 +0200 http://bitbucket.org/pypy/pypy/changeset/4effc72e379f/
Log: hg merge default 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 @@ -316,7 +316,7 @@ other_len = len(other) cmp = _memcmp(value, other, min(len(value), len(other))) elif isinstance(w_other, W_BytesObject): - other = self._op_val(space, w_other) + other = w_other.bytes_w(space) other_len = len(other) cmp = _memcmp(value, other, min(len(value), len(other))) else: @@ -360,18 +360,9 @@ self._data += w_other.getdata() return self - if isinstance(w_other, W_BytesObject): - self._inplace_add(self._op_val(space, w_other)) - else: - self._inplace_add(space.readbuf_w(w_other)) + self._data += self._op_val(space, w_other) return self - @specialize.argtype(1) - def _inplace_add(self, other): - resizelist_hint(self._data, len(self._data) + len(other)) - for i in range(len(other)): - self._data.append(other[i]) - def descr_inplace_mul(self, space, w_times): try: times = space.getindex_w(w_times, space.w_OverflowError) @@ -430,8 +421,10 @@ def descr_extend(self, space, w_other): if isinstance(w_other, W_BytearrayObject): self._data += w_other.getdata() + elif isinstance(w_other, W_BytesObject): # performance only + self._data += w_other.bytes_w(space) else: - self._inplace_add(makebytesdata_w(space, w_other)) + self._data += makebytesdata_w(space, w_other) def descr_insert(self, space, w_idx, w_other): where = space.int_w(w_idx) @@ -462,20 +455,13 @@ if isinstance(w_other, W_BytearrayObject): return self._new(self.getdata() + w_other.getdata()) - if isinstance(w_other, W_BytesObject): - return self._add(self._op_val(space, w_other)) - try: - buffer = space.readbuf_w(w_other) + byte_string = self._op_val(space, w_other) except OperationError as e: if e.match(space, space.w_TypeError): return space.w_NotImplemented raise - return self._add(buffer) - - @specialize.argtype(1) - def _add(self, other): - return self._new(self.getdata() + [other[i] for i in range(len(other))]) + return self._new(self.getdata() + list(byte_string)) def descr_reverse(self, space): self.getdata().reverse() 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 @@ -398,11 +398,19 @@ assert b == bytearray(b'obe') def test_iadd(self): - b = bytearray(b'abc') + b = b0 = bytearray(b'abc') b += b'def' assert b == b'abcdef' - assert isinstance(b, bytearray) + assert b is b0 raises(TypeError, b.__iadd__, "") + # + b += bytearray(b'XX') + assert b == b'abcdefXX' + assert b is b0 + # + b += memoryview(b'ABC') + assert b == b'abcdefXXABC' + assert b is b0 def test_add(self): b1 = bytearray(b"abc") @@ -471,6 +479,10 @@ raises(TypeError, b.extend, [object()]) raises(TypeError, b.extend, "unicode") + b = bytearray(b'abc') + b.extend(memoryview(b'def')) + assert b == bytearray(b'abcdef') + def test_extend_calls_len_or_lengthhint(self): class BadLen(object): def __iter__(self): return iter(range(10)) diff --git a/rpython/annotator/test/test_annrpython.py b/rpython/annotator/test/test_annrpython.py --- a/rpython/annotator/test/test_annrpython.py +++ b/rpython/annotator/test/test_annrpython.py @@ -4665,6 +4665,17 @@ a = self.RPythonAnnotator() assert a.build_types(h, [int]).const == 456 + def test_list_plus_equal_string(self): + def f(n): + lst = [chr(n), chr(n + 1)] + if n < 100: + lst.append(chr(n + 2)) + lst += str(n) + return lst + a = self.RPythonAnnotator() + s = a.build_types(f, [int]) + assert isinstance(listitem(s), annmodel.SomeChar) + def g(n): return [0, 1, 2, n] diff --git a/rpython/rtyper/test/test_rstr.py b/rpython/rtyper/test/test_rstr.py --- a/rpython/rtyper/test/test_rstr.py +++ b/rpython/rtyper/test/test_rstr.py @@ -1059,7 +1059,7 @@ l = [const('a'), const('b')] else: l = [const('a')] - l += y + l += y # list += string return const('').join(l) assert self.ll_to_string(self.interpret(f, [1, _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit