From e6fbee0981611bed51a628dde77ee75c82609111 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 10 Sep 2017 15:15:41 +1000 Subject: py/builtinhelp: Simplify code slightly by extracting object type. Reduces code size by about 10 bytes. --- py/builtinhelp.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'py/builtinhelp.c') diff --git a/py/builtinhelp.c b/py/builtinhelp.c index dbcd6e00f..e10e48b7d 100644 --- a/py/builtinhelp.c +++ b/py/builtinhelp.c @@ -136,20 +136,19 @@ STATIC void mp_help_print_obj(const mp_obj_t obj) { } #endif + mp_obj_type_t *type = mp_obj_get_type(obj); + // try to print something sensible about the given object mp_print_str(MP_PYTHON_PRINTER, "object "); mp_obj_print(obj, PRINT_STR); - mp_printf(MP_PYTHON_PRINTER, " is of type %s\n", mp_obj_get_type_str(obj)); + mp_printf(MP_PYTHON_PRINTER, " is of type %q\n", type->name); mp_map_t *map = NULL; - if (MP_OBJ_IS_TYPE(obj, &mp_type_module)) { + if (type == &mp_type_module) { map = mp_obj_dict_get_map(mp_obj_module_get_globals(obj)); } else { - mp_obj_type_t *type; - if (MP_OBJ_IS_TYPE(obj, &mp_type_type)) { - type = obj; - } else { - type = mp_obj_get_type(obj); + if (type == &mp_type_type) { + type = MP_OBJ_TO_PTR(obj); } if (type->locals_dict != MP_OBJ_NULL && MP_OBJ_IS_TYPE(type->locals_dict, &mp_type_dict)) { map = mp_obj_dict_get_map(type->locals_dict); -- cgit v1.2.3 From da8c4c2653b5121070f8c2872aead79d67d28441 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 12 Sep 2017 16:03:52 +1000 Subject: py/builtinhelp: Change signature of help text var from pointer to array. As a pointer (const char *) it takes up an extra word of storage which is in RAM. --- ports/cc3200/misc/help.c | 2 +- ports/esp8266/help.c | 2 +- ports/stm32/help.c | 2 +- ports/teensy/help.c | 2 +- ports/zephyr/help.c | 2 +- py/builtin.h | 2 +- py/builtinhelp.c | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) (limited to 'py/builtinhelp.c') diff --git a/ports/cc3200/misc/help.c b/ports/cc3200/misc/help.c index 739303e19..ea0c9501d 100644 --- a/ports/cc3200/misc/help.c +++ b/ports/cc3200/misc/help.c @@ -27,6 +27,6 @@ #include "py/builtin.h" -const char *cc3200_help_text = "Welcome to MicroPython!\n" +const char cc3200_help_text[] = "Welcome to MicroPython!\n" "For online help please visit http://micropython.org/help/.\n" "For further help on a specific object, type help(obj)\n"; diff --git a/ports/esp8266/help.c b/ports/esp8266/help.c index 2035cdd6c..0a851f4c4 100644 --- a/ports/esp8266/help.c +++ b/ports/esp8266/help.c @@ -26,7 +26,7 @@ #include "py/builtin.h" -const char *esp_help_text = +const char esp_help_text[] = "Welcome to MicroPython!\n" "\n" "For online docs please visit http://docs.micropython.org/en/latest/esp8266/ .\n" diff --git a/ports/stm32/help.c b/ports/stm32/help.c index ea0b6921b..f9d97b70d 100644 --- a/ports/stm32/help.c +++ b/ports/stm32/help.c @@ -26,7 +26,7 @@ #include "py/builtin.h" -const char *stm32_help_text = +const char stm32_help_text[] = "Welcome to MicroPython!\n" "\n" "For online help please visit http://micropython.org/help/.\n" diff --git a/ports/teensy/help.c b/ports/teensy/help.c index ebe4bed6b..a2370c04d 100644 --- a/ports/teensy/help.c +++ b/ports/teensy/help.c @@ -26,7 +26,7 @@ #include "py/builtin.h" -const char *teensy_help_text = +const char teensy_help_text[] = "Welcome to MicroPython!\n" "\n" "For online help please visit http://micropython.org/help/.\n" diff --git a/ports/zephyr/help.c b/ports/zephyr/help.c index 0c7f27940..becc203f6 100644 --- a/ports/zephyr/help.c +++ b/ports/zephyr/help.c @@ -26,7 +26,7 @@ #include "py/builtin.h" -const char *zephyr_help_text = +const char zephyr_help_text[] = "Welcome to MicroPython!\n" "\n" "Control commands:\n" diff --git a/py/builtin.h b/py/builtin.h index a637b6e22..84b99a8a4 100644 --- a/py/builtin.h +++ b/py/builtin.h @@ -118,6 +118,6 @@ extern const mp_obj_module_t mp_module_webrepl; extern const mp_obj_module_t mp_module_framebuf; extern const mp_obj_module_t mp_module_btree; -extern const char *MICROPY_PY_BUILTINS_HELP_TEXT; +extern const char MICROPY_PY_BUILTINS_HELP_TEXT[]; #endif // MICROPY_INCLUDED_PY_BUILTIN_H diff --git a/py/builtinhelp.c b/py/builtinhelp.c index e10e48b7d..c9992906d 100644 --- a/py/builtinhelp.c +++ b/py/builtinhelp.c @@ -32,7 +32,7 @@ #if MICROPY_PY_BUILTINS_HELP -const char *mp_help_default_text = +const char mp_help_default_text[] = "Welcome to MicroPython!\n" "\n" "For online docs please visit http://docs.micropython.org/\n" -- cgit v1.2.3