Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: py3.5
Changeset: r91882:6159e89116af
Date: 2017-07-15 19:05 +0200
http://bitbucket.org/pypy/pypy/changeset/6159e89116af/

Log:    (ronan, vaclav) Improve performance of bytearray.extend() by
        rewriting some of it at app-level

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
@@ -750,20 +750,12 @@
                     "cannot convert a (unicode) str object to bytes")
 
     # sequence of bytes
-    w_iter = space.iter(w_source)
-    length_hint = space.length_hint(w_source, 0)
-    builder = StringBuilder(length_hint)
-    while True:
-        try:
-            w_item = space.next(w_iter)
-        except OperationError as e:
-            if not e.match(space, space.w_StopIteration):
-                raise
-            break
-        value = space.byte_w(w_item)
-        builder.append(value)
-    return builder.build()
-
+    w_result = space.appexec([w_source], """(seq):
+        result = bytearray()
+        for i in seq:
+            result.append(i)
+        return result""")
+    return w_result.getdata()
 
 W_BytesObject.typedef = TypeDef(
     "bytes", None, None, "read",
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to