[pypy-commit] pypy py3.5: merge py3.5-str-opt
plan_rich
pypy.commits at gmail.com
Thu Oct 13 11:50:35 EDT 2016
Author: Richard Plangger <planrichi at gmail.com>
Branch: py3.5
Changeset: r87762:f81c41204b32
Date: 2016-10-13 17:49 +0200
http://bitbucket.org/pypy/pypy/changeset/f81c41204b32/
Log: merge py3.5-str-opt
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
@@ -187,7 +187,7 @@
@unwrap_spec(encoding='str_or_None', errors='str_or_None')
def descr_init(self, space, w_source=None, encoding=None, errors=None):
assert isinstance(self, W_BytearrayObject)
- data = newbytesdata_w(space, w_source, encoding, errors)
+ data = [c for c in newbytesdata_w(space, w_source, encoding, errors)]
self.data = resizable_list_supporting_raw_ptr(data)
def descr_repr(self, space):
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
@@ -533,7 +533,7 @@
if (w_source and space.is_w(space.type(w_source), space.w_bytes) and
space.is_w(w_stringtype, space.w_bytes)):
return w_source
- value = ''.join(newbytesdata_w(space, w_source, encoding, errors))
+ value = newbytesdata_w(space, w_source, encoding, errors)
w_obj = space.allocate_instance(W_BytesObject, w_stringtype)
W_BytesObject.__init__(w_obj, value)
return w_obj
@@ -699,7 +699,7 @@
if encoding is not None or errors is not None:
raise oefmt(space.w_TypeError,
"encoding or errors without string argument")
- return []
+ return b""
# Some object with __bytes__ special method
w_bytes_method = space.lookup(w_source, "__bytes__")
if w_bytes_method is not None:
@@ -707,7 +707,7 @@
if not space.isinstance_w(w_bytes, space.w_bytes):
raise oefmt(space.w_TypeError,
"__bytes__ returned non-bytes (type '%T')", w_bytes)
- return [c for c in space.bytes_w(w_bytes)]
+ return space.bytes_w(w_bytes)
# Is it an integer?
# Note that we're calling space.getindex_w() instead of space.int_w().
try:
@@ -721,7 +721,7 @@
if encoding is not None or errors is not None:
raise oefmt(space.w_TypeError,
"encoding or errors without string argument")
- return ['\0'] * count
+ return '\0' * count
# Unicode with encoding
if space.isinstance_w(w_source, space.w_unicode):
if encoding is None:
@@ -740,7 +740,7 @@
if not space.isinstance_w(w_bytes, space.w_bytes):
raise oefmt(space.w_TypeError,
"__bytes__ returned non-bytes (type '%T')", w_bytes)
- return [c for c in space.bytes_w(w_bytes)]
+ return space.bytes_w(w_bytes)
return _convert_from_buffer_or_iterable(space, w_source)
def _convert_from_buffer_or_iterable(space, w_source):
@@ -751,7 +751,7 @@
if not e.match(space, space.w_TypeError):
raise
else:
- return [c for c in buf.as_str()]
+ return buf.as_str()
if space.isinstance_w(w_source, space.w_unicode):
raise oefmt(space.w_TypeError,
@@ -760,8 +760,7 @@
# sequence of bytes
w_iter = space.iter(w_source)
length_hint = space.length_hint(w_source, 0)
- data = newlist_hint(length_hint)
- extended = 0
+ builder = StringBuilder(length_hint)
while True:
try:
w_item = space.next(w_iter)
@@ -770,11 +769,8 @@
raise
break
value = getbytevalue(space, w_item)
- data.append(value)
- extended += 1
- if extended < length_hint:
- resizelist_hint(data, extended)
- return data
+ builder.append(value)
+ return builder.build()
W_BytesObject.typedef = TypeDef(
diff --git a/pypy/objspace/std/test/test_bytesobject.py b/pypy/objspace/std/test/test_bytesobject.py
--- a/pypy/objspace/std/test/test_bytesobject.py
+++ b/pypy/objspace/std/test/test_bytesobject.py
@@ -106,10 +106,6 @@
raises(TypeError, bytes.fromhex, True)
raises(ValueError, bytes.fromhex, "hello world")
- def test_format_c_overflow(self):
- raises(OverflowError, b'{0:c}'.format, -1)
- raises(OverflowError, b'{0:c}'.format, 256)
-
def test_format_wrongtype(self):
for int_format in '%d', '%o', '%x':
exc_info = raises(TypeError, int_format.__mod__, '123')
diff --git a/pypy/objspace/std/test/test_unicodeobject.py b/pypy/objspace/std/test/test_unicodeobject.py
--- a/pypy/objspace/std/test/test_unicodeobject.py
+++ b/pypy/objspace/std/test/test_unicodeobject.py
@@ -1006,3 +1006,4 @@
assert u'A\u0345\u03a3'.lower() == u'a\u0345\u03c2'
assert u'A\u03a3\u0345'.lower() == u'a\u03c2\u0345'
assert u'\u03a3\u0345 '.lower() == u'\u03c3\u0345 '
+
diff --git a/rpython/rlib/runicode.py b/rpython/rlib/runicode.py
--- a/rpython/rlib/runicode.py
+++ b/rpython/rlib/runicode.py
@@ -1358,7 +1358,6 @@
if size == 0:
return STR('')
-
pos = 0
while pos < size:
ch = s[pos]
More information about the pypy-commit
mailing list