Skip to content

Commit 4775a08

Browse files
committed
pybricks/pybricks: Optimize package init without REPL.
We can save 92 bytes by omitting the logic to import everything, which is only used in the REPL. And since pb_package_pybricks_init() is only called on a clean state, we can get away doing the current initialization without catching exceptions.
1 parent 4e1eac2 commit 4775a08

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pybricks/pybricks.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ MP_REGISTER_MODULE(MP_QSTR_pybricks_c, pb_package_pybricks);
6161
MP_REGISTER_MODULE(MP_QSTR_pybricks, pb_package_pybricks);
6262
#endif
6363

64+
#if PYBRICKS_OPT_COMPILER
6465
/**
6566
* import * from all builtin Pybricks and MicroPython modules.
6667
*/
@@ -102,6 +103,14 @@ void pb_package_pybricks_init(bool import_all) {
102103
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
103104
}
104105
}
106+
#else
107+
// Cheaper implementation of the above. This is sufficient on builds without
108+
// the compiler, since the following deterministic action should not raise
109+
// exceptions as it is only called before executing anything else.
110+
void pb_package_pybricks_init(bool import_all) {
111+
pb_type_Color_reset();
112+
}
113+
#endif // PYBRICKS_OPT_COMPILER
105114

106115
void pb_package_pybricks_deinit(void) {
107116
// Disconnect from remote.

0 commit comments

Comments
 (0)