@@ -291,9 +291,7 @@ _PyIncrementalNewlineDecoder_decode(PyObject *_self,
291291 kind = PyUnicode_KIND (modified );
292292 out = PyUnicode_DATA (modified );
293293 PyUnicode_WRITE (kind , PyUnicode_DATA (modified ), 0 , '\r' );
294- memcpy (out + PyUnicode_KIND_SIZE (kind , 1 ),
295- PyUnicode_DATA (output ),
296- PyUnicode_KIND_SIZE (kind , output_len ));
294+ memcpy (out + kind , PyUnicode_DATA (output ), kind * output_len );
297295 Py_DECREF (output );
298296 output = modified ; /* output remains ready */
299297 self -> pendingcr = 0 ;
@@ -336,15 +334,15 @@ _PyIncrementalNewlineDecoder_decode(PyObject *_self,
336334 for the \r *byte* with the libc's optimized memchr.
337335 */
338336 if (seennl == SEEN_LF || seennl == 0 ) {
339- only_lf = (memchr (in_str , '\r' , PyUnicode_KIND_SIZE ( kind , len ) ) == NULL );
337+ only_lf = (memchr (in_str , '\r' , kind * len ) == NULL );
340338 }
341339
342340 if (only_lf ) {
343341 /* If not already seen, quick scan for a possible "\n" character.
344342 (there's nothing else to be done, even when in translation mode)
345343 */
346344 if (seennl == 0 &&
347- memchr (in_str , '\n' , PyUnicode_KIND_SIZE ( kind , len ) ) != NULL ) {
345+ memchr (in_str , '\n' , kind * len ) != NULL ) {
348346 Py_ssize_t i = 0 ;
349347 for (;;) {
350348 Py_UCS4 c ;
@@ -403,7 +401,7 @@ _PyIncrementalNewlineDecoder_decode(PyObject *_self,
403401 when there is something to translate. On the other hand,
404402 we already know there is a \r byte, so chances are high
405403 that something needs to be done. */
406- translated = PyMem_Malloc (PyUnicode_KIND_SIZE ( kind , len ) );
404+ translated = PyMem_Malloc (kind * len );
407405 if (translated == NULL ) {
408406 PyErr_NoMemory ();
409407 goto error ;
@@ -1576,15 +1574,14 @@ textiowrapper_read(textio *self, PyObject *args)
15761574static char *
15771575find_control_char (int kind , char * s , char * end , Py_UCS4 ch )
15781576{
1579- int size = PyUnicode_KIND_SIZE (kind , 1 );
15801577 for (;;) {
15811578 while (PyUnicode_READ (kind , s , 0 ) > ch )
1582- s += size ;
1579+ s += kind ;
15831580 if (PyUnicode_READ (kind , s , 0 ) == ch )
15841581 return s ;
15851582 if (s == end )
15861583 return NULL ;
1587- s += size ;
1584+ s += kind ;
15881585 }
15891586}
15901587
@@ -1593,14 +1590,13 @@ _PyIO_find_line_ending(
15931590 int translated , int universal , PyObject * readnl ,
15941591 int kind , char * start , char * end , Py_ssize_t * consumed )
15951592{
1596- int size = PyUnicode_KIND_SIZE (kind , 1 );
1597- Py_ssize_t len = ((char * )end - (char * )start )/size ;
1593+ Py_ssize_t len = ((char * )end - (char * )start )/kind ;
15981594
15991595 if (translated ) {
16001596 /* Newlines are already translated, only search for \n */
16011597 char * pos = find_control_char (kind , start , end , '\n' );
16021598 if (pos != NULL )
1603- return (pos - start )/size + 1 ;
1599+ return (pos - start )/kind + 1 ;
16041600 else {
16051601 * consumed = len ;
16061602 return -1 ;
@@ -1616,20 +1612,20 @@ _PyIO_find_line_ending(
16161612 /* Fast path for non-control chars. The loop always ends
16171613 since the Unicode string is NUL-terminated. */
16181614 while (PyUnicode_READ (kind , s , 0 ) > '\r' )
1619- s += size ;
1615+ s += kind ;
16201616 if (s >= end ) {
16211617 * consumed = len ;
16221618 return -1 ;
16231619 }
16241620 ch = PyUnicode_READ (kind , s , 0 );
1625- s += size ;
1621+ s += kind ;
16261622 if (ch == '\n' )
1627- return (s - start )/size ;
1623+ return (s - start )/kind ;
16281624 if (ch == '\r' ) {
16291625 if (PyUnicode_READ (kind , s , 0 ) == '\n' )
1630- return (s - start )/size + 1 ;
1626+ return (s - start )/kind + 1 ;
16311627 else
1632- return (s - start )/size ;
1628+ return (s - start )/kind ;
16331629 }
16341630 }
16351631 }
@@ -1642,13 +1638,13 @@ _PyIO_find_line_ending(
16421638 if (readnl_len == 1 ) {
16431639 char * pos = find_control_char (kind , start , end , nl [0 ]);
16441640 if (pos != NULL )
1645- return (pos - start )/size + 1 ;
1641+ return (pos - start )/kind + 1 ;
16461642 * consumed = len ;
16471643 return -1 ;
16481644 }
16491645 else {
16501646 char * s = start ;
1651- char * e = end - (readnl_len - 1 )* size ;
1647+ char * e = end - (readnl_len - 1 )* kind ;
16521648 char * pos ;
16531649 if (e < s )
16541650 e = s ;
@@ -1662,14 +1658,14 @@ _PyIO_find_line_ending(
16621658 break ;
16631659 }
16641660 if (i == readnl_len )
1665- return (pos - start )/size + readnl_len ;
1666- s = pos + size ;
1661+ return (pos - start )/kind + readnl_len ;
1662+ s = pos + kind ;
16671663 }
16681664 pos = find_control_char (kind , e , end , nl [0 ]);
16691665 if (pos == NULL )
16701666 * consumed = len ;
16711667 else
1672- * consumed = (pos - start )/size ;
1668+ * consumed = (pos - start )/kind ;
16731669 return -1 ;
16741670 }
16751671 }
@@ -1738,8 +1734,8 @@ _textiowrapper_readline(textio *self, Py_ssize_t limit)
17381734 endpos = _PyIO_find_line_ending (
17391735 self -> readtranslate , self -> readuniversal , self -> readnl ,
17401736 kind ,
1741- ptr + PyUnicode_KIND_SIZE ( kind , start ) ,
1742- ptr + PyUnicode_KIND_SIZE ( kind , line_len ) ,
1737+ ptr + kind * start ,
1738+ ptr + kind * line_len ,
17431739 & consumed );
17441740 if (endpos >= 0 ) {
17451741 endpos += start ;
0 commit comments