py: Use str_to_int function in more places to reduce code size.

This commit is contained in:
Damien George 2014-12-21 21:07:03 +00:00
parent 01039b5bd8
commit 81836c28b3

View File

@ -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. // *num if at least one digit was parsed.
static int str_to_int(const char *str, int *num) { static int str_to_int(const char *str, int *num) {
const char *s = str; const char *s = str;
if (unichar_isdigit(*s)) { if ('0' <= *s && *s <= '9') {
*num = 0; *num = 0;
do { do {
*num = *num * 10 + (*s - '0'); *num = *num * 10 + (*s - '0');
s++; s++;
} }
while (unichar_isdigit(*s)); while ('0' <= *s && *s <= '9');
} }
return s - str; 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++]); width = mp_obj_get_int(args[arg_i++]);
str++; str++;
} else { } else {
for (; str < top && '0' <= *str && *str <= '9'; str++) { str += str_to_int((const char*)str, &width);
width = width * 10 + *str - '0';
}
} }
} }
int prec = -1; 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++; str++;
} else { } else {
prec = 0; prec = 0;
for (; str < top && '0' <= *str && *str <= '9'; str++) { str += str_to_int((const char*)str, &prec);
prec = prec * 10 + *str - '0';
}
} }
} }
} }