mirror of
https://github.com/micropython/micropython.git
synced 2025-07-21 21:11:12 +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;
|
||||
|
||||
// determine what the string is
|
||||
if (str + 2 < top && (str[0] | 0x20) == 'i') {
|
||||
// string starts with 'i', should be 'inf' or 'infinity' (case insensitive)
|
||||
if ((str[1] | 0x20) == 'n' && (str[2] | 0x20) == 'f') {
|
||||
// inf
|
||||
if (str + 2 < top && (str[0] | 0x20) == 'i' && (str[1] | 0x20) == 'n' && (str[2] | 0x20) == 'f') {
|
||||
// 'inf' or 'infinity' (case insensitive)
|
||||
str += 3;
|
||||
dec_val = (mp_float_t)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') {
|
||||
// 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
|
||||
} 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 {
|
||||
// string should be a decimal number
|
||||
parse_dec_in_t in = PARSE_DEC_IN_INTG;
|
||||
|
Reference in New Issue
Block a user