Skip to content

Commit 87d1658

Browse files
committed
Issue #12805: Make bytes.join and bytearray.join faster when the separator is empty.
Patch by Serhiy Storchaka.
1 parent 91d25f0 commit 87d1658

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #12805: Make bytes.join and bytearray.join faster when the separator
14+
is empty. Patch by Serhiy Storchaka.
15+
1316
- Issue #6074: Ensure cached bytecode files can always be updated by the
1417
user that created them, even when the source file is read-only.
1518

Objects/stringlib/join.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable)
9494

9595
/* Catenate everything. */
9696
p = STRINGLIB_STR(res);
97+
if (!seplen) {
98+
/* fast path */
99+
for (i = 0; i < nbufs; i++) {
100+
Py_ssize_t n = buffers[i].len;
101+
char *q = buffers[i].buf;
102+
Py_MEMCPY(p, q, n);
103+
p += n;
104+
}
105+
goto done;
106+
}
97107
for (i = 0; i < nbufs; i++) {
98108
Py_ssize_t n;
99109
char *q;

0 commit comments

Comments
 (0)