summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-10-11 18:58:41 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-10-11 18:58:41 (GMT)
commite459a0877e0ca76e3af1057722a0e366395c661f (patch)
tree6bc90d91766d28fa23af071a2b7a5a2b6d4b28e7
parent2c3b2302adb1bb00b6050afc30eacbc023379b93 (diff)
downloadcpython-e459a0877e0ca76e3af1057722a0e366395c661f.zip
cpython-e459a0877e0ca76e3af1057722a0e366395c661f.tar.gz
cpython-e459a0877e0ca76e3af1057722a0e366395c661f.tar.bz2
Issue #13136: speed up conversion between different character widths.
-rw-r--r--Objects/unicodeobject.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 091f964..fc42a28 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -177,12 +177,21 @@ extern "C" {
buffer where the result characters are written to. */
#define _PyUnicode_CONVERT_BYTES(from_type, to_type, begin, end, to) \
do { \
- const from_type *iter_; to_type *to_; \
- for (iter_ = (begin), to_ = (to_type *)(to); \
- iter_ < (end); \
- ++iter_, ++to_) { \
- *to_ = (to_type)*iter_; \
+ to_type *_to = (to_type *) to; \
+ const from_type *_iter = (begin); \
+ const from_type *_end = (end); \
+ Py_ssize_t n = (_end) - (_iter); \
+ const from_type *_unrolled_end = \
+ _iter + (n & ~ (Py_ssize_t) 3); \
+ while (_iter < (_unrolled_end)) { \
+ _to[0] = (to_type) _iter[0]; \
+ _to[1] = (to_type) _iter[1]; \
+ _to[2] = (to_type) _iter[2]; \
+ _to[3] = (to_type) _iter[3]; \
+ _iter += 4; _to += 4; \
} \
+ while (_iter < (_end)) \
+ *_to++ = (to_type) *_iter++; \
} while (0)
/* The Unicode string has been modified: reset the hash */