Skip to content

Commit 3ea9b92

Browse files
authored
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.
1 parent 8e6321e commit 3ea9b92

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Objects/unicodeobject.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4702,8 +4702,9 @@ ascii_decode(const char *start, const char *end, Py_UCS1 *dest)
47024702
const char *p = start;
47034703

47044704
#if SIZEOF_SIZE_T <= SIZEOF_VOID_P
4705-
assert(_Py_IS_ALIGNED(dest, ALIGNOF_SIZE_T));
4706-
if (_Py_IS_ALIGNED(p, ALIGNOF_SIZE_T)) {
4705+
if (_Py_IS_ALIGNED(p, ALIGNOF_SIZE_T)
4706+
&& _Py_IS_ALIGNED(dest, ALIGNOF_SIZE_T))
4707+
{
47074708
/* Fast path, see in STRINGLIB(utf8_decode) for
47084709
an explanation. */
47094710
/* Help allocation */
@@ -4948,9 +4949,7 @@ unicode_decode_utf8_writer(_PyUnicodeWriter *writer,
49484949
const char *end = s + size;
49494950
Py_ssize_t decoded = 0;
49504951
Py_UCS1 *dest = (Py_UCS1*)writer->data + writer->pos * writer->kind;
4951-
if (writer->kind == PyUnicode_1BYTE_KIND
4952-
&& _Py_IS_ALIGNED(dest, ALIGNOF_SIZE_T))
4953-
{
4952+
if (writer->kind == PyUnicode_1BYTE_KIND) {
49544953
decoded = ascii_decode(s, end, dest);
49554954
writer->pos += decoded;
49564955

0 commit comments

Comments
 (0)