diff options
author | Victor Stinner <vstinner@python.org> | 2024-06-03 06:45:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-03 06:45:20 (GMT) |
commit | 3ea9b92086240b2f38a74c6945e7a723b480cefe (patch) | |
tree | 53c03de52a2063549320abb0685182b07e485f44 /Objects | |
parent | 8e6321efd72d12263398994e59c5216edcada3c0 (diff) | |
download | cpython-3ea9b92086240b2f38a74c6945e7a723b480cefe.zip cpython-3ea9b92086240b2f38a74c6945e7a723b480cefe.tar.gz cpython-3ea9b92086240b2f38a74c6945e7a723b480cefe.tar.bz2 |
gh-119396: Optimize unicode_decode_utf8_writer() (#119957)
Optimize unicode_decode_utf8_writer()
Take the ascii_decode() fast-path even if dest is not aligned on
size_t bytes.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/unicodeobject.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 1278275..53160f1 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -4702,8 +4702,9 @@ ascii_decode(const char *start, const char *end, Py_UCS1 *dest) const char *p = start; #if SIZEOF_SIZE_T <= SIZEOF_VOID_P - assert(_Py_IS_ALIGNED(dest, ALIGNOF_SIZE_T)); - if (_Py_IS_ALIGNED(p, ALIGNOF_SIZE_T)) { + if (_Py_IS_ALIGNED(p, ALIGNOF_SIZE_T) + && _Py_IS_ALIGNED(dest, ALIGNOF_SIZE_T)) + { /* Fast path, see in STRINGLIB(utf8_decode) for an explanation. */ /* Help allocation */ @@ -4948,9 +4949,7 @@ unicode_decode_utf8_writer(_PyUnicodeWriter *writer, const char *end = s + size; Py_ssize_t decoded = 0; Py_UCS1 *dest = (Py_UCS1*)writer->data + writer->pos * writer->kind; - if (writer->kind == PyUnicode_1BYTE_KIND - && _Py_IS_ALIGNED(dest, ALIGNOF_SIZE_T)) - { + if (writer->kind == PyUnicode_1BYTE_KIND) { decoded = ascii_decode(s, end, dest); writer->pos += decoded; |