[pypy-issue] [issue866] [PATCH] join is slow about 2x slower than Python

Armin Rigo tracker at bugs.pypy.org
Sat Sep 10 19:43:44 CEST 2011


Armin Rigo <armin.rigo at gmail.com> added the comment:

I think it's worth it anyway.  Another patch attached, trying to get all checks
out of loops for the common case; can someone measure it?

----------
nosy: +arigo

________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue866>
________________________________________
-------------- next part --------------
diff -r ca11f6ae93ae pypy/objspace/std/stringobject.py
--- a/pypy/objspace/std/stringobject.py	Fri Sep 09 22:59:33 2011 -0700
+++ b/pypy/objspace/std/stringobject.py	Sat Sep 10 19:43:24 2011 +0200
@@ -364,6 +364,9 @@
     reslen = len(self) * (size - 1)
     for i in range(size):
         w_s = list_w[i]
+        if isinstance(w_s, W_StringObject):
+            reslen += len(w_s._value)
+            continue
         if not space.is_true(space.isinstance(w_s, space.w_str)):
             if space.is_true(space.isinstance(w_s, space.w_unicode)):
                 # we need to rebuild w_list here, because the original
@@ -378,10 +381,14 @@
         reslen += len(space.str_w(w_s))
 
     sb = StringBuilder(reslen)
-    for i in range(size):
-        if self and i != 0:
+    if len(self) > 0:
+        sb.append(space.str_w(list_w[0]))
+        for i in range(1, size):
             sb.append(self)
-        sb.append(space.str_w(list_w[i]))
+            sb.append(space.str_w(list_w[i]))
+    else:
+        for i in range(size):
+            sb.append(space.str_w(list_w[i]))
     return space.wrap(sb.build())
 
 def str_rjust__String_ANY_ANY(space, w_self, w_arg, w_fillchar):


More information about the pypy-issue mailing list