22
33#if STRINGLIB_IS_UNICODE
44
5- /* Mask to check or force alignment of a pointer to C 'long' boundaries */
6- #define LONG_PTR_MASK (size_t) (SIZEOF_LONG - 1)
7-
85/* Mask to quickly check whether a C 'long' contains a
96 non-ASCII, UTF8-encoded char. */
107#if (SIZEOF_LONG == 8 )
@@ -25,7 +22,7 @@ STRINGLIB(utf8_decode)(const char **inptr, const char *end,
2522{
2623 Py_UCS4 ch ;
2724 const char * s = * inptr ;
28- const char * aligned_end = (const char * ) (( size_t ) end & ~ LONG_PTR_MASK );
25+ const char * aligned_end = (const char * ) _Py_ALIGN_DOWN ( end , SIZEOF_LONG );
2926 STRINGLIB_CHAR * p = dest + * outpos ;
3027
3128 while (s < end ) {
@@ -39,7 +36,7 @@ STRINGLIB(utf8_decode)(const char **inptr, const char *end,
3936 First, check if we can do an aligned read, as most CPUs have
4037 a penalty for unaligned reads.
4138 */
42- if (!(( size_t ) s & LONG_PTR_MASK )) {
39+ if (_Py_IS_ALIGNED ( s , SIZEOF_LONG )) {
4340 /* Help register allocation */
4441 register const char * _s = s ;
4542 register STRINGLIB_CHAR * _p = p ;
@@ -453,7 +450,7 @@ STRINGLIB(utf16_decode)(const unsigned char **inptr, const unsigned char *e,
453450{
454451 Py_UCS4 ch ;
455452 const unsigned char * aligned_end =
456- (const unsigned char * ) (( size_t ) e & ~ LONG_PTR_MASK );
453+ (const unsigned char * ) _Py_ALIGN_DOWN ( e , SIZEOF_LONG );
457454 const unsigned char * q = * inptr ;
458455 STRINGLIB_CHAR * p = dest + * outpos ;
459456 /* Offsets from q for retrieving byte pairs in the right order. */
@@ -468,7 +465,7 @@ STRINGLIB(utf16_decode)(const unsigned char **inptr, const unsigned char *e,
468465 Py_UCS4 ch2 ;
469466 /* First check for possible aligned read of a C 'long'. Unaligned
470467 reads are more expensive, better to defer to another iteration. */
471- if (!(( size_t ) q & LONG_PTR_MASK )) {
468+ if (_Py_IS_ALIGNED ( q , SIZEOF_LONG )) {
472469 /* Fast path for runs of in-range non-surrogate chars. */
473470 register const unsigned char * _q = q ;
474471 while (_q < aligned_end ) {
@@ -565,7 +562,6 @@ STRINGLIB(utf16_decode)(const unsigned char **inptr, const unsigned char *e,
565562#undef FAST_CHAR_MASK
566563#undef STRIPPED_MASK
567564#undef SWAB
568- #undef LONG_PTR_MASK
569565
570566
571567Py_LOCAL_INLINE (void )
@@ -588,7 +584,7 @@ STRINGLIB(utf16_encode)(unsigned short *out,
588584 _PyUnicode_CONVERT_BYTES (STRINGLIB_CHAR , unsigned short , in , end , out );
589585# endif
590586 } else {
591- const STRINGLIB_CHAR * unrolled_end = in + (len & ~ ( Py_ssize_t ) 3 );
587+ const STRINGLIB_CHAR * unrolled_end = in + _Py_SIZE_ROUND_DOWN (len , 4 );
592588 while (in < unrolled_end ) {
593589 out [0 ] = SWAB2 (in [0 ]);
594590 out [1 ] = SWAB2 (in [1 ]);
0 commit comments