From d921dd6d61be29866e62b923d3e37859829188bd Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 2 Oct 2025 13:33:25 -0500 Subject: [PATCH] py/objmodule: Avoid interning a string unnecessarily. If the lookup of the module name less the leading "u" is going to succeed, it's already a qstr (because that qstr is the key in `mp_builtin_extensible_module_map`). So, use a function that will avoid interning it if it's not already. For example, if you `import unavailable` it used to intern the string `navailable`, but now it won't. Signed-off-by: Jeff Epler --- py/objmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/objmodule.c b/py/objmodule.c index 8c26cc55a7..2ffa7847f4 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -212,7 +212,7 @@ mp_obj_t mp_module_get_builtin(qstr module_name, bool extensible) { if (module_name_str[0] != 'u') { return MP_OBJ_NULL; } - elem = mp_map_lookup((mp_map_t *)&mp_builtin_extensible_module_map, MP_OBJ_NEW_QSTR(qstr_from_strn(module_name_str + 1, module_name_len - 1)), MP_MAP_LOOKUP); + elem = mp_map_lookup((mp_map_t *)&mp_builtin_extensible_module_map, MP_OBJ_NEW_QSTR(qstr_find_strn(module_name_str + 1, module_name_len - 1)), MP_MAP_LOOKUP); #endif if (!elem) {