py/frozenmod: Store frozen module names together, to quickly scan them.
This commit is contained in:
parent
1b0aab621b
commit
17f324b836
@ -32,21 +32,22 @@
|
|||||||
|
|
||||||
#if MICROPY_MODULE_FROZEN
|
#if MICROPY_MODULE_FROZEN
|
||||||
|
|
||||||
extern const uint16_t mp_frozen_sizes[];
|
extern const char mp_frozen_names[];
|
||||||
|
extern const uint32_t mp_frozen_sizes[];
|
||||||
extern const char mp_frozen_content[];
|
extern const char mp_frozen_content[];
|
||||||
|
|
||||||
mp_lexer_t *mp_find_frozen_module(const char *str, int len) {
|
mp_lexer_t *mp_find_frozen_module(const char *str, int len) {
|
||||||
const uint16_t *sz_ptr = mp_frozen_sizes;
|
const char *name = mp_frozen_names;
|
||||||
const char *s = mp_frozen_content;
|
|
||||||
|
|
||||||
while (*sz_ptr) {
|
size_t offset = 0;
|
||||||
int l = strlen(s);
|
for (int i = 0; *name != 0; i++) {
|
||||||
if (l == len && !memcmp(str, s, l)) {
|
int l = strlen(name);
|
||||||
s += l + 1;
|
if (l == len && !memcmp(str, name, l)) {
|
||||||
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR_, s, *sz_ptr, 0);
|
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR_, mp_frozen_content + offset, mp_frozen_sizes[i], 0);
|
||||||
return lex;
|
return lex;
|
||||||
}
|
}
|
||||||
s += (l + 1) + (*sz_ptr++ + 1);
|
name += l + 1;
|
||||||
|
offset += mp_frozen_sizes[i] + 1;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -37,17 +37,21 @@ for dirpath, dirnames, filenames in os.walk(root):
|
|||||||
modules.append((fullpath[root_len + 1:], st))
|
modules.append((fullpath[root_len + 1:], st))
|
||||||
|
|
||||||
print("#include <stdint.h>")
|
print("#include <stdint.h>")
|
||||||
print("const uint16_t mp_frozen_sizes[] = {")
|
print("const char mp_frozen_names[] = {")
|
||||||
|
for f, st in modules:
|
||||||
|
m = module_name(f)
|
||||||
|
print('"%s\\0"' % m)
|
||||||
|
print('"\\0"};')
|
||||||
|
|
||||||
|
print("const uint32_t mp_frozen_sizes[] = {")
|
||||||
|
|
||||||
for f, st in modules:
|
for f, st in modules:
|
||||||
print("%d," % st.st_size)
|
print("%d," % st.st_size)
|
||||||
|
|
||||||
print("0};")
|
print("};")
|
||||||
|
|
||||||
print("const char mp_frozen_content[] = {")
|
print("const char mp_frozen_content[] = {")
|
||||||
for f, st in modules:
|
for f, st in modules:
|
||||||
m = module_name(f)
|
|
||||||
print('"%s\\0"' % m)
|
|
||||||
data = open(sys.argv[1] + "/" + f, "rb").read()
|
data = open(sys.argv[1] + "/" + f, "rb").read()
|
||||||
# Python2 vs Python3 tricks
|
# Python2 vs Python3 tricks
|
||||||
data = repr(data)
|
data = repr(data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user