Skip to content
Snippets Groups Projects
Commit 7cf26ca4 authored by Yonatan Goldschmidt's avatar Yonatan Goldschmidt Committed by Damien George
Browse files

py/obj: Optimise small-int comparison to 0 in mp_obj_is_true.

Instead of converting to a small-int at runtime this can be done at compile
time, then we only have a simple comparison during runtime.  This reduces
code size on some ports (e.g -4 on qemu-arm, -52 on unix nanbox), and for
others at least doesn't increase code size.
parent faf3d3e9
Branches
Tags
No related merge requests found
......@@ -113,7 +113,7 @@ bool mp_obj_is_true(mp_obj_t arg) {
} else if (arg == mp_const_none) {
return 0;
} else if (mp_obj_is_small_int(arg)) {
if (MP_OBJ_SMALL_INT_VALUE(arg) == 0) {
if (arg == MP_OBJ_NEW_SMALL_INT(0)) {
return 0;
} else {
return 1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment