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

Side by Side Diff: Objects/bytearrayobject.c

Issue 26574: replace_interleave can be optimized for single character byte strings
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:
View unified diff | Download patch
« no previous file with comments | « Misc/ACKS ('k') | Objects/bytesobject.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* PyByteArray (bytearray) implementation */ 1 /* PyByteArray (bytearray) implementation */
2 2
3 #define PY_SSIZE_T_CLEAN 3 #define PY_SSIZE_T_CLEAN
4 #include "Python.h" 4 #include "Python.h"
5 #include "structmember.h" 5 #include "structmember.h"
6 #include "bytes_methods.h" 6 #include "bytes_methods.h"
7 #include "bytesobject.h" 7 #include "bytesobject.h"
8 #include "pystrhex.h" 8 #include "pystrhex.h"
9 9
10 /*[clinic input] 10 /*[clinic input]
(...skipping 1687 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 } 1698 }
1699 result_len = count * to_len + self_len; 1699 result_len = count * to_len + self_len;
1700 1700
1701 if (! (result = (PyByteArrayObject *) 1701 if (! (result = (PyByteArrayObject *)
1702 PyByteArray_FromStringAndSize(NULL, result_len)) ) 1702 PyByteArray_FromStringAndSize(NULL, result_len)) )
1703 return NULL; 1703 return NULL;
1704 1704
1705 self_s = PyByteArray_AS_STRING(self); 1705 self_s = PyByteArray_AS_STRING(self);
1706 result_s = PyByteArray_AS_STRING(result); 1706 result_s = PyByteArray_AS_STRING(result);
1707 1707
1708 /* TODO: special case single character, which doesn't need memcpy */ 1708 if (to_len > 1) {
1709 1709 /* Lay the first one down (guaranteed this will occur) */
1710 /* Lay the first one down (guaranteed this will occur) */
1711 Py_MEMCPY(result_s, to_s, to_len);
1712 result_s += to_len;
1713 count -= 1;
1714
1715 for (i=0; i<count; i++) {
1716 *result_s++ = *self_s++;
1717 Py_MEMCPY(result_s, to_s, to_len); 1710 Py_MEMCPY(result_s, to_s, to_len);
1718 result_s += to_len; 1711 result_s += to_len;
1712 count -= 1;
1713
1714 for (i = 0; i < count; i++) {
1715 *result_s++ = *self_s++;
1716 Py_MEMCPY(result_s, to_s, to_len);
1717 result_s += to_len;
1718 }
1719 }
1720 else {
1721 result_s[0] = to_s[0];
1722 result_s += to_len;
1723 count -= 1;
1724 for (i = 0; i < count; i++) {
1725 *result_s++ = *self_s++;
1726 result_s[0] = to_s[0];
1727 result_s += to_len;
1728 }
1719 } 1729 }
1720 1730
1721 /* Copy the rest of the original string */ 1731 /* Copy the rest of the original string */
1722 Py_MEMCPY(result_s, self_s, self_len-i); 1732 Py_MEMCPY(result_s, self_s, self_len-i);
1723 1733
1724 return result; 1734 return result;
1725 } 1735 }
1726 1736
1727 /* Special case for deleting a single character */ 1737 /* Special case for deleting a single character */
1728 /* len(self)>=1, len(from)==1, to="", maxcount>=1 */ 1738 /* len(self)>=1, len(from)==1, to="", maxcount>=1 */
(...skipping 1490 matching lines...) Expand 10 before | Expand all | Expand 10 after
3219 } 3229 }
3220 it = PyObject_GC_New(bytesiterobject, &PyByteArrayIter_Type); 3230 it = PyObject_GC_New(bytesiterobject, &PyByteArrayIter_Type);
3221 if (it == NULL) 3231 if (it == NULL)
3222 return NULL; 3232 return NULL;
3223 it->it_index = 0; 3233 it->it_index = 0;
3224 Py_INCREF(seq); 3234 Py_INCREF(seq);
3225 it->it_seq = (PyByteArrayObject *)seq; 3235 it->it_seq = (PyByteArrayObject *)seq;
3226 _PyObject_GC_TRACK(it); 3236 _PyObject_GC_TRACK(it);
3227 return (PyObject *)it; 3237 return (PyObject *)it;
3228 } 3238 }
OLDNEW
« no previous file with comments | « Misc/ACKS ('k') | Objects/bytesobject.c » ('j') | no next file with comments »

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