File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,11 @@ def hexlify_to_str(b):
62
62
sys .path .append (sys .path [0 ] + "/../py" )
63
63
import makeqstrdata as qstrutil
64
64
65
+ # Threshold of str length below which it will be turned into a qstr when freezing.
66
+ # This helps to reduce frozen code size because qstrs are more efficient to encode
67
+ # as objects than full mp_obj_str_t instances.
68
+ PERSISTENT_STR_INTERN_THRESHOLD = 25
69
+
65
70
66
71
class MPYReadError (Exception ):
67
72
def __init__ (self , filename , msg ):
@@ -1187,6 +1192,9 @@ def read_obj(reader, segments):
1187
1192
reader .read_byte () # read and discard null terminator
1188
1193
if obj_type == MP_PERSISTENT_OBJ_STR :
1189
1194
obj = str_cons (buf , "utf8" )
1195
+ if len (obj ) < PERSISTENT_STR_INTERN_THRESHOLD :
1196
+ if not global_qstrs .find_by_str (obj ):
1197
+ global_qstrs .add (obj )
1190
1198
elif obj_type == MP_PERSISTENT_OBJ_BYTES :
1191
1199
obj = buf
1192
1200
elif obj_type == MP_PERSISTENT_OBJ_INT :
You can’t perform that action at this time.
0 commit comments