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.
This commit is contained in:
Victor Stinner 2024-06-03 08:45:20 +02:00 committed by GitHub
parent 8e6321efd7
commit 3ea9b92086
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 5 deletions

View File

@ -4702,8 +4702,9 @@ ascii_decode(const char *start, const char *end, Py_UCS1 *dest)
const char *p = start; const char *p = start;
#if SIZEOF_SIZE_T <= SIZEOF_VOID_P #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 /* Fast path, see in STRINGLIB(utf8_decode) for
an explanation. */ an explanation. */
/* Help allocation */ /* Help allocation */
@ -4948,9 +4949,7 @@ unicode_decode_utf8_writer(_PyUnicodeWriter *writer,
const char *end = s + size; const char *end = s + size;
Py_ssize_t decoded = 0; Py_ssize_t decoded = 0;
Py_UCS1 *dest = (Py_UCS1*)writer->data + writer->pos * writer->kind; Py_UCS1 *dest = (Py_UCS1*)writer->data + writer->pos * writer->kind;
if (writer->kind == PyUnicode_1BYTE_KIND if (writer->kind == PyUnicode_1BYTE_KIND) {
&& _Py_IS_ALIGNED(dest, ALIGNOF_SIZE_T))
{
decoded = ascii_decode(s, end, dest); decoded = ascii_decode(s, end, dest);
writer->pos += decoded; writer->pos += decoded;