Skip to content

Commit 1a0dcb5

Browse files
committed
makeqstrdata: reclaim some more bytes on some translations
If a translation only has unicode code points 255 and below, the "values" array can be 8 bits instead of 16 bits. This reclaims some code size, e.g., in a local build, trinket_m0 / en_US reclaimed 112 bytes and de_DE reclaimed 104 bytes. However, languages like zh_Latn_pinyin, which use code points above 255, did not benefit.
1 parent 879e104 commit 1a0dcb5

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

py/makeqstrdata.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,10 @@ def compute_huffman_coding(translations, qstrs, compression_filename):
131131
print("// values", values, "lengths", len(lengths), lengths)
132132
print("// estimated total memory size", len(lengths) + 2*len(values) + sum(len(cb[u]) for u in all_strings_concat))
133133
print("//", values, lengths)
134+
values_type = "uint16_t" if max(ord(u) for u in values) > 255 else "uint8_t"
134135
with open(compression_filename, "w") as f:
135136
f.write("const uint8_t lengths[] = {{ {} }};\n".format(", ".join(map(str, lengths))))
136-
f.write("const uint16_t values[] = {{ {} }};\n".format(", ".join(str(ord(u)) for u in values)))
137+
f.write("const {} values[] = {{ {} }};\n".format(values_type, ", ".join(str(ord(u)) for u in values)))
137138
return values, lengths
138139

139140
def decompress(encoding_table, length, encoded):

0 commit comments

Comments
 (0)