From 6f7b0da6bcbcb5a873d8315e49db4096895fc2eb Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sat, 20 Oct 2012 23:08:34 +0200 Subject: Issue #12805: Make bytes.join and bytearray.join faster when the separator is empty. Patch by Serhiy Storchaka. --- Objects/stringlib/join.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'Objects/stringlib') diff --git a/Objects/stringlib/join.h b/Objects/stringlib/join.h index 21753cb504..d1d6e532c5 100644 --- a/Objects/stringlib/join.h +++ b/Objects/stringlib/join.h @@ -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; -- cgit v1.2.1