]> granicus.if.org Git - python/commitdiff
Issue #12805: Make bytes.join and bytearray.join faster when the separator is empty.
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 20 Oct 2012 21:08:34 +0000 (23:08 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 20 Oct 2012 21:08:34 +0000 (23:08 +0200)
Patch by Serhiy Storchaka.

Misc/NEWS
Objects/stringlib/join.h

index c105585675fafc2cc904379a9ede9ad529a295d4..e6a5f24b769204d56cf8417f9573daf651690f9c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1?
 Core and Builtins
 -----------------
 
+- Issue #12805: Make bytes.join and bytearray.join faster when the separator
+  is empty.  Patch by Serhiy Storchaka.
+
 - Issue #6074: Ensure cached bytecode files can always be updated by the
   user that created them, even when the source file is read-only.
 
index 21753cb5041cc25d01277834b6cb71b9c2938fff..d1d6e532c57294699ff5d601f006f87fd95b876d 100644 (file)
@@ -94,6 +94,16 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable)
 
     /* Catenate everything. */
     p = STRINGLIB_STR(res);
+    if (!seplen) {
+        /* fast path */
+        for (i = 0; i < nbufs; i++) {
+            Py_ssize_t n = buffers[i].len;
+            char *q = buffers[i].buf;
+            Py_MEMCPY(p, q, n);
+            p += n;
+        }
+        goto done;
+    }
     for (i = 0; i < nbufs; i++) {
         Py_ssize_t n;
         char *q;