From 81836c28b346c5158e6fc8a79b74a8caa7211dd7 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 21 Dec 2014 21:07:03 +0000 Subject: py: Use str_to_int function in more places to reduce code size. --- py/objstr.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'py/objstr.c') diff --git a/py/objstr.c b/py/objstr.c index 1bb89dda91..7cd44471ec 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -790,13 +790,13 @@ STATIC mp_obj_t str_rstrip(mp_uint_t n_args, const mp_obj_t *args) { // *num if at least one digit was parsed. static int str_to_int(const char *str, int *num) { const char *s = str; - if (unichar_isdigit(*s)) { + if ('0' <= *s && *s <= '9') { *num = 0; do { *num = *num * 10 + (*s - '0'); s++; } - while (unichar_isdigit(*s)); + while ('0' <= *s && *s <= '9'); } return s - str; } @@ -1331,9 +1331,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o width = mp_obj_get_int(args[arg_i++]); str++; } else { - for (; str < top && '0' <= *str && *str <= '9'; str++) { - width = width * 10 + *str - '0'; - } + str += str_to_int((const char*)str, &width); } } int prec = -1; @@ -1347,9 +1345,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o str++; } else { prec = 0; - for (; str < top && '0' <= *str && *str <= '9'; str++) { - prec = prec * 10 + *str - '0'; - } + str += str_to_int((const char*)str, &prec); } } } -- cgit v1.2.3