From 40d431d1bbb7928ab399bf892e90cf232a83e2b9 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 8 Apr 2022 14:05:23 +1000 Subject: [PATCH] tools/mpy-tool.py: Optimise freezing of str when str data is a qstr. Signed-off-by: Damien George --- tools/mpy-tool.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index e3a812ebe0..f4a8ef6420 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -478,6 +478,12 @@ class GlobalQStrList: def get_by_index(self, i): return self.qstrs[i] + def find_by_str(self, s): + for q in self.qstrs: + if q is not None and q.str == s: + return q + return None + class MPFunTable: def __repr__(self): @@ -633,6 +639,9 @@ class CompiledModule: else: return "MP_ROM_PTR(&mp_const_empty_bytes_obj)" if is_str_type(obj): + q = global_qstrs.find_by_str(obj) + if q: + return "MP_ROM_QSTR(%s)" % q.qstr_id obj = bytes_cons(obj, "utf8") obj_type = "mp_type_str" else: