Skip to content

Commit 81836c2

Browse files
committed
py: Use str_to_int function in more places to reduce code size.
1 parent 01039b5 commit 81836c2

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

py/objstr.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -790,13 +790,13 @@ STATIC mp_obj_t str_rstrip(mp_uint_t n_args, const mp_obj_t *args) {
790790
// *num if at least one digit was parsed.
791791
static int str_to_int(const char *str, int *num) {
792792
const char *s = str;
793-
if (unichar_isdigit(*s)) {
793+
if ('0' <= *s && *s <= '9') {
794794
*num = 0;
795795
do {
796796
*num = *num * 10 + (*s - '0');
797797
s++;
798798
}
799-
while (unichar_isdigit(*s));
799+
while ('0' <= *s && *s <= '9');
800800
}
801801
return s - str;
802802
}
@@ -1331,9 +1331,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o
13311331
width = mp_obj_get_int(args[arg_i++]);
13321332
str++;
13331333
} else {
1334-
for (; str < top && '0' <= *str && *str <= '9'; str++) {
1335-
width = width * 10 + *str - '0';
1336-
}
1334+
str += str_to_int((const char*)str, &width);
13371335
}
13381336
}
13391337
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
13471345
str++;
13481346
} else {
13491347
prec = 0;
1350-
for (; str < top && '0' <= *str && *str <= '9'; str++) {
1351-
prec = prec * 10 + *str - '0';
1352-
}
1348+
str += str_to_int((const char*)str, &prec);
13531349
}
13541350
}
13551351
}

0 commit comments

Comments
 (0)