@@ -48,16 +48,17 @@ invalid_comma_type(Py_UCS4 presentation_type)
4848 returns -1 on error.
4949*/
5050static int
51- get_integer (PyObject * str , Py_ssize_t * pos , Py_ssize_t end ,
51+ get_integer (PyObject * str , Py_ssize_t * ppos , Py_ssize_t end ,
5252 Py_ssize_t * result )
5353{
54- Py_ssize_t accumulator , digitval ;
54+ Py_ssize_t accumulator , digitval , pos = * ppos ;
5555 int numdigits ;
56+ int kind = PyUnicode_KIND (str );
57+ void * data = PyUnicode_DATA (str );
58+
5659 accumulator = numdigits = 0 ;
57- for (;;(* pos )++ , numdigits ++ ) {
58- if (* pos >= end )
59- break ;
60- digitval = Py_UNICODE_TODECIMAL (PyUnicode_READ_CHAR (str , * pos ));
60+ for (; pos < end ; pos ++ , numdigits ++ ) {
61+ digitval = Py_UNICODE_TODECIMAL (PyUnicode_READ (kind , data , pos ));
6162 if (digitval < 0 )
6263 break ;
6364 /*
@@ -69,10 +70,12 @@ get_integer(PyObject *str, Py_ssize_t *pos, Py_ssize_t end,
6970 if (accumulator > (PY_SSIZE_T_MAX - digitval ) / 10 ) {
7071 PyErr_Format (PyExc_ValueError ,
7172 "Too many decimal digits in format string" );
73+ * ppos = pos ;
7274 return -1 ;
7375 }
7476 accumulator = accumulator * 10 + digitval ;
7577 }
78+ * ppos = pos ;
7679 * result = accumulator ;
7780 return numdigits ;
7881}
@@ -150,9 +153,11 @@ parse_internal_render_format_spec(PyObject *format_spec,
150153 char default_align )
151154{
152155 Py_ssize_t pos = start ;
156+ int kind = PyUnicode_KIND (format_spec );
157+ void * data = PyUnicode_DATA (format_spec );
153158 /* end-pos is used throughout this code to specify the length of
154159 the input string */
155- #define READ_spec (index ) PyUnicode_READ_CHAR(format_spec , index)
160+ #define READ_spec (index ) PyUnicode_READ(kind, data , index)
156161
157162 Py_ssize_t consumed ;
158163 int align_specified = 0 ;
@@ -402,13 +407,15 @@ parse_number(PyObject *s, Py_ssize_t pos, Py_ssize_t end,
402407 Py_ssize_t * n_remainder , int * has_decimal )
403408{
404409 Py_ssize_t remainder ;
410+ int kind = PyUnicode_KIND (s );
411+ void * data = PyUnicode_DATA (s );
405412
406- while (pos < end && Py_ISDIGIT (PyUnicode_READ_CHAR ( s , pos )))
413+ while (pos < end && Py_ISDIGIT (PyUnicode_READ ( kind , data , pos )))
407414 ++ pos ;
408415 remainder = pos ;
409416
410417 /* Does remainder start with a decimal point? */
411- * has_decimal = pos < end && PyUnicode_READ_CHAR ( s , remainder ) == '.' ;
418+ * has_decimal = pos < end && PyUnicode_READ ( kind , data , remainder ) == '.' ;
412419
413420 /* Skip the decimal point. */
414421 if (* has_decimal )
0 commit comments