From dfc6c6299c3ce3788412e054b8381d11283eb4a9 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 8 Apr 2022 13:07:25 +1000 Subject: [PATCH] tools/mpy-tool.py: Optimise freezing of empty str and bytes objects. Signed-off-by: Damien George --- tools/mpy-tool.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index 17dd8704ae..6a769f7b40 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -621,6 +621,11 @@ class CompiledModule: elif obj is Ellipsis: return "MP_ROM_PTR(&mp_const_ellipsis_obj)" elif is_str_type(obj) or is_bytes_type(obj): + if len(obj) == 0: + if is_str_type(obj): + return "MP_ROM_QSTR(MP_QSTR_)" + else: + return "MP_ROM_PTR(&mp_const_empty_bytes_obj)" if is_str_type(obj): obj = bytes_cons(obj, "utf8") obj_type = "mp_type_str"