Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e459a08

Browse files
committed
Issue #13136: speed up conversion between different character widths.
1 parent 2c3b230 commit e459a08

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

Objects/unicodeobject.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,21 @@ extern "C" {
177177
buffer where the result characters are written to. */
178178
#define _PyUnicode_CONVERT_BYTES(from_type, to_type, begin, end, to) \
179179
do { \
180-
const from_type *iter_; to_type *to_; \
181-
for (iter_ = (begin), to_ = (to_type *)(to); \
182-
iter_ < (end); \
183-
++iter_, ++to_) { \
184-
*to_ = (to_type)*iter_; \
180+
to_type *_to = (to_type *) to; \
181+
const from_type *_iter = (begin); \
182+
const from_type *_end = (end); \
183+
Py_ssize_t n = (_end) - (_iter); \
184+
const from_type *_unrolled_end = \
185+
_iter + (n & ~ (Py_ssize_t) 3); \
186+
while (_iter < (_unrolled_end)) { \
187+
_to[0] = (to_type) _iter[0]; \
188+
_to[1] = (to_type) _iter[1]; \
189+
_to[2] = (to_type) _iter[2]; \
190+
_to[3] = (to_type) _iter[3]; \
191+
_iter += 4; _to += 4; \
185192
} \
193+
while (_iter < (_end)) \
194+
*_to++ = (to_type) *_iter++; \
186195
} while (0)
187196

188197
/* The Unicode string has been modified: reset the hash */

0 commit comments

Comments
 (0)