mirror of
https://github.com/micropython/micropython.git
synced 2025-08-10 04:32:05 +02:00
py/parsenum: Further reduce code size in check for inf/nan.
A few more bytes can be saved by not using nested `if`s (4 bytes for `build-MICROBIT/py/parsenum.o`, 8 bytes for RPI_PICO firmware). This commit is better viewed with whitespace changes hidden, because two blocks were reindented (e.g., `git show -b`). Signed-off-by: Jeff Epler <jepler@gmail.com>
This commit is contained in:
committed by
Damien George
parent
5eb9755259
commit
c1629dc2ff
@@ -252,24 +252,18 @@ parse_start:
|
|||||||
const char *str_val_start = str;
|
const char *str_val_start = str;
|
||||||
|
|
||||||
// determine what the string is
|
// determine what the string is
|
||||||
if (str + 2 < top && (str[0] | 0x20) == 'i') {
|
if (str + 2 < top && (str[0] | 0x20) == 'i' && (str[1] | 0x20) == 'n' && (str[2] | 0x20) == 'f') {
|
||||||
// string starts with 'i', should be 'inf' or 'infinity' (case insensitive)
|
// 'inf' or 'infinity' (case insensitive)
|
||||||
if ((str[1] | 0x20) == 'n' && (str[2] | 0x20) == 'f') {
|
str += 3;
|
||||||
// inf
|
dec_val = (mp_float_t)INFINITY;
|
||||||
str += 3;
|
if (str + 4 < top && (str[0] | 0x20) == 'i' && (str[1] | 0x20) == 'n' && (str[2] | 0x20) == 'i' && (str[3] | 0x20) == 't' && (str[4] | 0x20) == 'y') {
|
||||||
dec_val = (mp_float_t)INFINITY;
|
// infinity
|
||||||
if (str + 4 < top && (str[0] | 0x20) == 'i' && (str[1] | 0x20) == 'n' && (str[2] | 0x20) == 'i' && (str[3] | 0x20) == 't' && (str[4] | 0x20) == 'y') {
|
str += 5;
|
||||||
// infinity
|
|
||||||
str += 5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (str + 2 < top && (str[0] | 0x20) == 'n') {
|
|
||||||
// string starts with 'n', should be 'nan' (case insensitive)
|
|
||||||
if ((str[1] | 0x20) == 'a' && (str[2] | 0x20) == 'n') {
|
|
||||||
// NaN
|
|
||||||
str += 3;
|
|
||||||
dec_val = MICROPY_FLOAT_C_FUN(nan)("");
|
|
||||||
}
|
}
|
||||||
|
} else if (str + 2 < top && (str[0] | 0x20) == 'n' && (str[1] | 0x20) == 'a' && (str[2] | 0x20) == 'n') {
|
||||||
|
// 'nan' (case insensitive)
|
||||||
|
str += 3;
|
||||||
|
dec_val = MICROPY_FLOAT_C_FUN(nan)("");
|
||||||
} else {
|
} else {
|
||||||
// string should be a decimal number
|
// string should be a decimal number
|
||||||
parse_dec_in_t in = PARSE_DEC_IN_INTG;
|
parse_dec_in_t in = PARSE_DEC_IN_INTG;
|
||||||
|
Reference in New Issue
Block a user