Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(13)

Unified Diff: Objects/bytesobject.c

Issue 26574: replace_interleave can be optimized for single character byte strings
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« Objects/bytearrayobject.c ('K') | « Objects/bytearrayobject.c ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Objects/bytesobject.c Mon Mar 07 14:52:46 2016 -0500
+++ b/Objects/bytesobject.c Wed Mar 16 18:19:41 2016 -0400
@@ -2464,22 +2464,29 @@
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 {
haypo 2016/03/17 00:45:05 same comments
+ 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 */
Py_MEMCPY(result_s, self_s, self_len-i);
-
return result;
}
« Objects/bytearrayobject.c ('K') | « Objects/bytearrayobject.c ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+