summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-01-03 18:08:45 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-01-03 18:08:45 +0200
commit17f324b83655e68b064f0637f5190000ea0e1f12 (patch)
tree33f43d0b6bcb8fc9daf6c20a8e3e003ad945e21b
parent1b0aab621baf081bf1cbeb38a29bd37fbc135cc7 (diff)
downloadmicropython-17f324b83655e68b064f0637f5190000ea0e1f12.tar.gz
micropython-17f324b83655e68b064f0637f5190000ea0e1f12.zip
py/frozenmod: Store frozen module names together, to quickly scan them.
-rw-r--r--py/frozenmod.c19
-rwxr-xr-xtools/make-frozen.py12
2 files changed, 18 insertions, 13 deletions
diff --git a/py/frozenmod.c b/py/frozenmod.c
index 440ae0aacf..9eea1dbcfc 100644
--- a/py/frozenmod.c
+++ b/py/frozenmod.c
@@ -32,21 +32,22 @@
#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[];
mp_lexer_t *mp_find_frozen_module(const char *str, int len) {
- const uint16_t *sz_ptr = mp_frozen_sizes;
- const char *s = mp_frozen_content;
+ const char *name = mp_frozen_names;
- while (*sz_ptr) {
- int l = strlen(s);
- if (l == len && !memcmp(str, s, l)) {
- s += l + 1;
- mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR_, s, *sz_ptr, 0);
+ size_t offset = 0;
+ for (int i = 0; *name != 0; i++) {
+ int l = strlen(name);
+ if (l == len && !memcmp(str, name, l)) {
+ mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR_, mp_frozen_content + offset, mp_frozen_sizes[i], 0);
return lex;
}
- s += (l + 1) + (*sz_ptr++ + 1);
+ name += l + 1;
+ offset += mp_frozen_sizes[i] + 1;
}
return NULL;
}
diff --git a/tools/make-frozen.py b/tools/make-frozen.py
index 7c3865cc41..e0c807c4ef 100755
--- a/tools/make-frozen.py
+++ b/tools/make-frozen.py
@@ -37,17 +37,21 @@ for dirpath, dirnames, filenames in os.walk(root):
modules.append((fullpath[root_len + 1:], st))
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:
print("%d," % st.st_size)
-print("0};")
+print("};")
print("const char mp_frozen_content[] = {")
for f, st in modules:
- m = module_name(f)
- print('"%s\\0"' % m)
data = open(sys.argv[1] + "/" + f, "rb").read()
# Python2 vs Python3 tricks
data = repr(data)