diff options
author | Ruben Vorderman <r.h.p.vorderman@lumc.nl> | 2024-06-17 12:21:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-17 12:21:58 +0200 |
commit | 945a89b48f017d711055da039899eaecc2eb7ddd (patch) | |
tree | 921d71b59d900b80f9670f630a783176bf6479e0 /Objects/stringlib/find_max_char.h | |
parent | 21866c8ed296524f0ca175c0f55b43744c2b30df (diff) | |
download | cpython-945a89b48f017d711055da039899eaecc2eb7ddd.tar.gz cpython-945a89b48f017d711055da039899eaecc2eb7ddd.zip |
gh-120196: Reuse find_max_char() for bytes objects (#120497)
Diffstat (limited to 'Objects/stringlib/find_max_char.h')
-rw-r--r-- | Objects/stringlib/find_max_char.h | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Objects/stringlib/find_max_char.h b/Objects/stringlib/find_max_char.h index b9ffdfc2e35..7ab3fc88b33 100644 --- a/Objects/stringlib/find_max_char.h +++ b/Objects/stringlib/find_max_char.h @@ -1,6 +1,7 @@ /* Finding the optimal width of unicode characters in a buffer */ -#if !STRINGLIB_IS_UNICODE +/* find_max_char for one-byte will work for bytes objects as well. */ +#if !STRINGLIB_IS_UNICODE && STRINGLIB_SIZEOF_CHAR > 1 # error "find_max_char.h is specific to Unicode" #endif @@ -20,19 +21,20 @@ Py_LOCAL_INLINE(Py_UCS4) STRINGLIB(find_max_char)(const STRINGLIB_CHAR *begin, const STRINGLIB_CHAR *end) { const unsigned char *p = (const unsigned char *) begin; + const unsigned char *_end = (const unsigned char *)end; - while (p < end) { + while (p < _end) { if (_Py_IS_ALIGNED(p, ALIGNOF_SIZE_T)) { /* Help register allocation */ const unsigned char *_p = p; - while (_p + SIZEOF_SIZE_T <= end) { + while (_p + SIZEOF_SIZE_T <= _end) { size_t value = *(const size_t *) _p; if (value & UCS1_ASCII_CHAR_MASK) return 255; _p += SIZEOF_SIZE_T; } p = _p; - if (p == end) + if (p == _end) break; } if (*p++ & 0x80) |