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

Delta Between Two Patch Sets: Objects/bytesobject.c

Issue 26574: replace_interleave can be optimized for single character byte strings
Left Patch Set: Created 3 years, 11 months ago
Right Patch Set: Created 3 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Objects/bytearrayobject.c ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* bytes object implementation */ 1 /* bytes object implementation */
2 2
3 #define PY_SSIZE_T_CLEAN 3 #define PY_SSIZE_T_CLEAN
4 4
5 #include "Python.h" 5 #include "Python.h"
6 6
7 #include "bytes_methods.h" 7 #include "bytes_methods.h"
8 #include "pystrhex.h" 8 #include "pystrhex.h"
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 2457 matching lines...) Expand 10 before | Expand all | Expand 10 after
2468 /* Lay the first one down (guaranteed this will occur) */ 2468 /* Lay the first one down (guaranteed this will occur) */
2469 Py_MEMCPY(result_s, to_s, to_len); 2469 Py_MEMCPY(result_s, to_s, to_len);
2470 result_s += to_len; 2470 result_s += to_len;
2471 count -= 1; 2471 count -= 1;
2472 2472
2473 for (i = 0; i < count; i++) { 2473 for (i = 0; i < count; i++) {
2474 *result_s++ = *self_s++; 2474 *result_s++ = *self_s++;
2475 Py_MEMCPY(result_s, to_s, to_len); 2475 Py_MEMCPY(result_s, to_s, to_len);
2476 result_s += to_len; 2476 result_s += to_len;
2477 } 2477 }
2478 } else { 2478 }
haypo 2016/03/17 00:45:05 same comments
2479 else {
2479 result_s[0] = to_s[0]; 2480 result_s[0] = to_s[0];
2480 result_s += to_len; 2481 result_s += to_len;
2481 count -= 1; 2482 count -= 1;
2482 for (i = 0; i < count; i++) { 2483 for (i = 0; i < count; i++) {
2483 *result_s++ = *self_s++; 2484 *result_s++ = *self_s++;
2484 result_s[0] = to_s[0]; 2485 result_s[0] = to_s[0];
2485 result_s += to_len; 2486 result_s += to_len;
2486 } 2487 }
2487 } 2488 }
2489
2488 /* Copy the rest of the original string */ 2490 /* Copy the rest of the original string */
2489 Py_MEMCPY(result_s, self_s, self_len-i); 2491 Py_MEMCPY(result_s, self_s, self_len-i);
2492
2490 return result; 2493 return result;
2491 } 2494 }
2492 2495
2493 /* Special case for deleting a single character */ 2496 /* Special case for deleting a single character */
2494 /* len(self)>=1, len(from)==1, to="", maxcount>=1 */ 2497 /* len(self)>=1, len(from)==1, to="", maxcount>=1 */
2495 Py_LOCAL(PyBytesObject *) 2498 Py_LOCAL(PyBytesObject *)
2496 replace_delete_single_character(PyBytesObject *self, 2499 replace_delete_single_character(PyBytesObject *self,
2497 char from_c, Py_ssize_t maxcount) 2500 char from_c, Py_ssize_t maxcount)
2498 { 2501 {
2499 char *self_s, *result_s; 2502 char *self_s, *result_s;
(...skipping 1682 matching lines...) Expand 10 before | Expand all | Expand 10 after
4182 4185
4183 str = _PyBytesWriter_Prepare(writer, str, size); 4186 str = _PyBytesWriter_Prepare(writer, str, size);
4184 if (str == NULL) 4187 if (str == NULL)
4185 return NULL; 4188 return NULL;
4186 4189
4187 Py_MEMCPY(str, bytes, size); 4190 Py_MEMCPY(str, bytes, size);
4188 str += size; 4191 str += size;
4189 4192
4190 return str; 4193 return str;
4191 } 4194 }
LEFTRIGHT

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