summaryrefslogtreecommitdiffstats
path: root/Objects/bytesobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/bytesobject.c')
-rw-r--r--Objects/bytesobject.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 602dea6..5b9006e 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -2464,17 +2464,27 @@ replace_interleave(PyBytesObject *self,
self_s = PyBytes_AS_STRING(self);
result_s = PyBytes_AS_STRING(result);
- /* TODO: special case single character, which doesn't need memcpy */
-
- /* Lay the first one down (guaranteed this will occur) */
- Py_MEMCPY(result_s, to_s, to_len);
- result_s += to_len;
- count -= 1;
-
- for (i=0; i<count; i++) {
- *result_s++ = *self_s++;
+ if (to_len > 1) {
+ /* Lay the first one down (guaranteed this will occur) */
Py_MEMCPY(result_s, to_s, to_len);
result_s += to_len;
+ count -= 1;
+
+ for (i = 0; i < count; i++) {
+ *result_s++ = *self_s++;
+ Py_MEMCPY(result_s, to_s, to_len);
+ result_s += to_len;
+ }
+ }
+ else {
+ result_s[0] = to_s[0];
+ result_s += to_len;
+ count -= 1;
+ for (i = 0; i < count; i++) {
+ *result_s++ = *self_s++;
+ result_s[0] = to_s[0];
+ result_s += to_len;
+ }
}
/* Copy the rest of the original string */