Skip to content

Commit

Permalink
pythongh-119396: Optimize unicode_decode_utf8_writer() (python#119957)
Browse files Browse the repository at this point in the history
Optimize unicode_decode_utf8_writer()

Take the ascii_decode() fast-path even if dest is not aligned on
size_t bytes.
  • Loading branch information
vstinner authored and mliezun committed Jun 3, 2024
1 parent 1a05635 commit 433ef5c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 433ef5c

Please sign in to comment.