diff options
author | Damien George <damien.p.george@gmail.com> | 2020-01-09 00:00:27 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2020-01-13 01:01:45 +1100 |
commit | d96cfd13e3a464862cecffb2718c6286b52c77b0 (patch) | |
tree | af399f8a18175155be1dfef08bc4ac51118b8bf8 /py/objnone.c | |
parent | 6f0c83f6e186eb163c4209f211ab1c959d255e81 (diff) |
py/obj: Add MICROPY_OBJ_IMMEDIATE_OBJS option to reduce code size.
This option (enabled by default for object representation A, B, C) makes
None/False/True objects immediate objects, ie they are no longer a concrete
object in ROM but are rather just values, eg None=0x6 for representation A.
Doing this saves a considerable amount of code size, due to these objects
being widely used:
bare-arm: -392 -0.591%
minimal x86: -252 -0.170% [incl +52(data)]
unix x64: -624 -0.125% [incl -128(data)]
unix nanbox: +0 +0.000%
stm32: -1940 -0.510% PYBV10
cc3200: -1216 -0.659%
esp8266: -404 -0.062% GENERIC
esp32: -732 -0.064% GENERIC[incl +48(data)]
nrf: -988 -0.675% pca10040
samd: -564 -0.556% ADAFRUIT_ITSYBITSY_M4_EXPRESS
Thanks go to @Jongy aka Yonatan Goldschmidt for the idea.
Diffstat (limited to 'py/objnone.c')
-rw-r--r-- | py/objnone.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/py/objnone.c b/py/objnone.c index da1031835..271a8543f 100644 --- a/py/objnone.c +++ b/py/objnone.c @@ -28,9 +28,11 @@ #include "py/obj.h" +#if !MICROPY_OBJ_IMMEDIATE_OBJS typedef struct _mp_obj_none_t { mp_obj_base_t base; } mp_obj_none_t; +#endif STATIC void none_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)self_in; @@ -48,4 +50,6 @@ const mp_obj_type_t mp_type_NoneType = { .unary_op = mp_generic_unary_op, }; +#if !MICROPY_OBJ_IMMEDIATE_OBJS const mp_obj_none_t mp_const_none_obj = {{&mp_type_NoneType}}; +#endif |