Issue #12805: Make bytes.join and bytearray.join faster when the separator is empty.

Patch by Serhiy Storchaka.
This commit is contained in:
Antoine Pitrou 2012-10-20 23:08:34 +02:00
parent 257c1323f7
commit 6f7b0da6bc
2 changed files with 13 additions and 0 deletions

View 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;