[pypy-svn] pypy bytearray: (mfoord) remove unnecessary loop in bytearray.join

mfoord commits-noreply at bitbucket.org
Fri Jan 21 12:46:57 CET 2011


Author: Michael Foord <michael at voidspace.org.uk>
Branch: bytearray
Changeset: r41120:b4acd2b63562
Date: 2011-01-21 10:29 +0100
http://bitbucket.org/pypy/pypy/changeset/b4acd2b63562/

Log:	(mfoord) remove unnecessary loop in bytearray.join

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
@@ -357,7 +357,8 @@
     if not list_w:
         return W_BytearrayObject([])
     data = w_self.data
-    reslen = 0
+
+    newdata = []
     for i in range(len(list_w)):
         w_s = list_w[i]
         if not (space.is_true(space.isinstance(w_s, space.w_str)) or
@@ -366,12 +367,10 @@
                 space.w_TypeError,
                 "sequence item %d: expected string, %s "
                 "found", i, space.type(w_s).getname(space, '?'))
-        reslen += len(space.bufferstr_w(w_s))
-    newdata = []
-    for i in range(len(list_w)):
+
         if data and i != 0:
             newdata.extend(data)
-        newdata.extend([c for c in space.bufferstr_w(list_w[i])])
+        newdata.extend([c for c in space.bufferstr_w(w_s)])
     return W_BytearrayObject(newdata)
 
 def str_decode__Bytearray_ANY_ANY(space, w_bytearray, w_encoding, w_errors):


More information about the Pypy-commit mailing list