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

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
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
haypo 2016/03/17 00:45:05 I don't think that this newline is needed.
1720 } else {
haypo 2016/03/17 00:45:05 PEP 7: need to rewrite this line as: } 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
haypo 2016/03/17 00:45:05 Please keep these empty lines that help for readab
1721 /* Copy the rest of the original string */ 1730 /* Copy the rest of the original string */
1722 Py_MEMCPY(result_s, self_s, self_len-i); 1731 Py_MEMCPY(result_s, self_s, self_len-i);
1723
1724 return result; 1732 return result;
1725 } 1733 }
1726 1734
1727 /* Special case for deleting a single character */ 1735 /* Special case for deleting a single character */
1728 /* len(self)>=1, len(from)==1, to="", maxcount>=1 */ 1736 /* len(self)>=1, len(from)==1, to="", maxcount>=1 */
1729 Py_LOCAL(PyByteArrayObject *) 1737 Py_LOCAL(PyByteArrayObject *)
1730 replace_delete_single_character(PyByteArrayObject *self, 1738 replace_delete_single_character(PyByteArrayObject *self,
1731 char from_c, Py_ssize_t maxcount) 1739 char from_c, Py_ssize_t maxcount)
1732 { 1740 {
1733 char *self_s, *result_s; 1741 char *self_s, *result_s;
(...skipping 1485 matching lines...) Expand 10 before | Expand all | Expand 10 after
3219 } 3227 }
3220 it = PyObject_GC_New(bytesiterobject, &PyByteArrayIter_Type); 3228 it = PyObject_GC_New(bytesiterobject, &PyByteArrayIter_Type);
3221 if (it == NULL) 3229 if (it == NULL)
3222 return NULL; 3230 return NULL;
3223 it->it_index = 0; 3231 it->it_index = 0;
3224 Py_INCREF(seq); 3232 Py_INCREF(seq);
3225 it->it_seq = (PyByteArrayObject *)seq; 3233 it->it_seq = (PyByteArrayObject *)seq;
3226 _PyObject_GC_TRACK(it); 3234 _PyObject_GC_TRACK(it);
3227 return (PyObject *)it; 3235 return (PyObject *)it;
3228 } 3236 }
OLDNEW
« no previous file with comments | « Misc/ACKS ('k') | Objects/bytesobject.c » ('j') | Objects/bytesobject.c » ('J')

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