Skip to content

Commit 72ee3ae

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

File tree

4 files changed

+64
-19
lines changed

4 files changed

+64
-19
lines changed

py/makeqstrdata.py

Lines changed: 61 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,64 @@
8989
"__repr__",
9090
"__setitem__",
9191
"__str__",
92+
"__bool__",
93+
"__pos__",
94+
"__neg__",
95+
"__invert__",
96+
"__abs__",
97+
"__float__",
98+
"__complex__",
99+
"___sizeof__",
100+
"__lt__",
101+
"__gt__",
102+
"__eq__",
103+
"__le__",
104+
"__ge__",
105+
"__ne__",
106+
"__contains__",
107+
"__iadd__",
108+
"__isub__",
109+
"__imul__",
110+
"__imatmul__",
111+
"__ifloordiv__",
112+
"__itruediv__",
113+
"__imod__",
114+
"__ipow__",
115+
"__ior__",
116+
"__ixor__",
117+
"__iand__",
118+
"__ilshift__",
119+
"__irshift__",
120+
"__add__",
121+
"__sub__",
122+
"__mul__",
123+
"__matmul__",
124+
"__floordiv__",
125+
"__truediv__",
126+
"__mod__",
127+
"__divmod__",
128+
"__pow__",
129+
"__or__",
130+
"__xor__",
131+
"__and__",
132+
"__lshift__",
133+
"__rshift__",
134+
"__radd__",
135+
"__rsub__",
136+
"__rmul__",
137+
"__rmatmul__",
138+
"__rfloordiv__",
139+
"__rtruediv__",
140+
"__rmod__",
141+
"__rpow__",
142+
"__ror__",
143+
"__rxor__",
144+
"__rand__",
145+
"__rlshift__",
146+
"__rrshift__",
147+
"__get__",
148+
"__set__",
149+
"__delete__",
92150
"ArithmeticError",
93151
"AssertionError",
94152
"AttributeError",
@@ -228,8 +286,6 @@
228286
]
229287

230288
# this must match the equivalent function in qstr.c
231-
232-
233289
def compute_hash(qstr, bytes_hash):
234290
hash = 5381
235291
for b in qstr:
@@ -305,16 +361,6 @@ def parse_input_headers(infiles):
305361

306362
# add the qstr to the list, with order number to retain original order in file
307363
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
318364
qstrs[ident] = Qstr(order, ident, qstr)
319365

320366
if not qcfgs:
@@ -374,11 +420,11 @@ def print_qstr_data(qstrs):
374420
q1_values = [q for q in qstrs.values() if q.order >= 0]
375421

376422
# 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):
423+
for q in sorted(q0_values, key=lambda x: x.qhash):
378424
print('QDEF0(MP_QSTR_%s, %d, %d, "%s")' % (q.ident, q.qhash, q.qlen, q.qdata))
379425

380426
# 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)):
427+
for q in sorted(q1_values, key=lambda x: x.qhash):
382428
print('QDEF1(MP_QSTR_%s, %d, %d, "%s")' % (q.ident, q.qhash, q.qlen, q.qdata))
383429

384430

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy