10000 py/qstr: Sort the first QSTR pool. · micropython/micropython@3570f0f · GitHub
[go: up one dir, main page]

Skip to content

Commit 3570f0f

Browse files
committed
py/qstr: Sort the first QSTR pool.
Signed-off-by: Amir Gonnen <amirgonnen@gmail.com>
1 parent b3b957d commit 3570f0f

File tree

4 files changed

+63
-19
lines changed

4 files changed

+63
-19
lines changed

py/makeqstrdata.py

Lines changed: 60 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
codepoint2name[ord("|")] = "pipe"
5353
codepoint2name[ord("~")] = "tilde"
5454

55-
# static qstrs, should be sorted
55+
# static qstrs, unsorted.
5656

5757
static_qstr_list = [
5858
"",
@@ -89,6 +89,63 @@
8989
"__repr__",
9090
"__setitem__",
9191
"__str__",
92+
"__bool__",
93+
"__pos__",
94+
"__neg__",
95+
"__invert__",
96+
"__abs__",
97+
"__float__",
98+
"__complex__",
99+
"__lt__",
100+
"__gt__",
101+
"__eq__",
102+
"__le__",
103+
"__ge__",
104+
"__ne__",
105+
"__contains__",
106+
"__iadd__",
107+
"__isub__",
108+
"__imul__",
109+
"__imatmul__",
110+
"__ifloordiv__",
111+
"__itruediv__",
112+
"__imod__",
113+
"__ipow__",
114+
"__ior__",
115+
"__ixor__",
116+
"__iand__",
117+
"__ilshift__",
118+
"__irshift__",
119+
"__add__",
120+
"__sub__",
121+
"__mul__",
122+
"__matmul__",
123+
"__floordiv__",
124+
"__truediv__",
125+
"__mod__",
126+
"__divmod__",
127+
"__pow__",
128+
"__or__",
129+
"__xor__",
130+
"__and__",
131+
"__lshift__",
132+
"__rshift__",
133+
"__radd__",
134+
"__rsub_ 10000 _",
135+
"__rmul__",
136+
"__rmatmul__",
137+
"__rfloordiv__",
138+
"__rtruediv__",
139+
"__rmod__",
140+
"__rpow__",
141+
"__ror__",
142+
"__rxor__",
143+
"__rand__",
144+
"__rlshift__",
145+
"__rrshift__",
146+
"__get__",
147+
"__set__",
148+
"__delete__",
92149
"ArithmeticError",
93150
"AssertionError",
94151
"AttributeError",
@@ -228,8 +285,6 @@
228285
]
229286

230287
# this must match the equivalent function in qstr.c
231-
232-
233288
def compute_hash(qstr, bytes_hash):
234289
hash = 5381
235290
for b in qstr:
@@ -305,16 +360,6 @@ def parse_input_headers(infiles):
305360

306361
# add the qstr to the list, with order number to retain original order in file
307362
order = len(qstrs)
308-
# but put special method names like __add__ at the top of list, so
309-
# that their id's fit into a byte
310-
if ident == "":
311-
# Sort empty qstr above all still
312-
order = -200000
313-
elif ident == "__dir__":
314-
# Put __dir__ after empty qstr for builtin dir() to work
315-
order = -190000
316-
elif ident.startswith("__"):
317-
order -= 100000
318363
qstrs[ident] = Qstr(order, ident, qstr)
319364

320365
if not qcfgs:
@@ -374,11 +419,11 @@ def print_qstr_data(qstrs):
374419
q1_values = [q for q in qstrs.values() if q.order >= 0]
375420

376421
# go through each qstr in pool 0 and print it out. pool0 has special sort.
377-
for q in sorted(q0_values, key=lambda x: x.order):
422+
for q in sorted(q0_values, key=lambda x: x.qhash):
378423
print('QDEF0(MP_QSTR_%s, %d, %d, "%s")' % (q.ident, q.qhash, q.qlen, q.qdata))
379424

380425
# go through each qstr in pool 1 and print it out. pool1 is regularly sorted.
381-
for q in sorted(q1_values, key=lambda x: (x.qhash, x.qlen)):
426+
for q in sorted(q1_values, key=lambda x: x.qhash):
382427
print('QDEF1(MP_QSTR_%s, %d, %d, "%s")' % (q.ident, q.qhash, q.qlen, q.qdata))
383428

384429

py/qstr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const qstr_pool_t mp_qstr_special_const_pool = {
121121
MP_QSTRspecial_const_number_of + 1, // corresponds to number of strings in array just below
122122
(qstr_hash_t *)mp_qstr_const_hashes0,
123123
(qstr_len_t *)mp_qstr_const_lengths0,
124-
false, // special constant qstrs are not sorted
124+
true,
125125
{
126126
#ifndef NO_QSTR
127127
#define QDEF0(id, hash, len, str) str,
@@ -246,7 +246,7 @@ qstr qstr_find_strn(const char *str, size_t str_len) {
246246
high = mid;
247247
} else {
248248
low = mid;
249-
if (cmp == 0) {
249+
if (MP_UNLIKELY(cmp == 0)) {
250250
while (low > 0 && pool->hashes[low - 1] == str_hash) {
251251
low--;
252252
}

tools/makemanifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def main():
415415
b'#include "py/emitglue.h"\n'
416416
b"extern const qstr_pool_t mp_qstr_const_pool;\n"
417417
b"const qstr_pool_t mp_qstr_frozen_const_pool = {\n"
418-
b" (qstr_pool_t*)&mp_qstr_const_pool, MP_QSTRnumber_of, 0, false, 0\n"
418+
b" (qstr_pool_t*)&mp_qstr_const_pool, MP_QSTRnumber_of, 0, 0, NULL, NULL, false, NULL\n"
419419
b"};\n"
420420
b'const char mp_frozen_names[] = { MP_FROZEN_STR_NAMES "\\0"};\n'
421421
b"const mp_raw_code_t *const mp_frozen_mpy_content[] = {NULL};\n"

tools/mpy-tool.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1793,7 +1793,6 @@ def main():
17931793
except MPYReadError as er:
17941794
print(er, file=sys.stderr)
17951795
sys.exit(1)
1796-
base_qstrs = {}
17971796

17981797
if args.hexdump:
17991798
hexdump_mpy(compiled_modules)

0 commit comments

Comments
 (0)
0