From 0c380748e0d055b6a77bb4afce6cf8d6f589c3a5 Mon Sep 17 00:00:00 2001 From: waterlike86 Date: Sat, 20 Apr 2019 08:39:04 +0800 Subject: [PATCH] emscripten.py: optimize check_all_implemented. (#8453) make it more efficient and skip it entirely when possible --- emscripten.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/emscripten.py b/emscripten.py index 15405124de1c..000a50d81354 100644 --- a/emscripten.py +++ b/emscripten.py @@ -852,8 +852,19 @@ def get_all_implemented(forwarded_json, metadata): def check_all_implemented(all_implemented, pre): - for requested in shared.Settings.ORIGINAL_EXPORTED_FUNCTIONS: - if not is_already_implemented(requested, pre, all_implemented): + # we are not checking anyway, so just skip this + if not shared.Settings.ERROR_ON_UNDEFINED_SYMBOLS and not shared.Settings.WARN_ON_UNDEFINED_SYMBOLS: + return + # the initial list of missing functions are those we expected to export, but were not implemented in compiled code + missing = list(set(shared.Settings.ORIGINAL_EXPORTED_FUNCTIONS) - set(all_implemented)) + # special-case malloc, EXPORTED by default for internal use, but we bake in a + # trivial allocator and warn at runtime if used in ASSERTIONS + if '_malloc' in missing: + missing.remove('_malloc') + + for requested in missing: + in_pre = ('function ' + asstr(requested)) in pre + if not in_pre: # could be a js library func if shared.Settings.ERROR_ON_UNDEFINED_SYMBOLS: exit_with_error('undefined exported function: "%s"', requested) @@ -861,15 +872,6 @@ def check_all_implemented(all_implemented, pre): logger.warning('undefined exported function: "%s"', requested) -def is_already_implemented(requested, pre, all_implemented): - is_implemented = requested in all_implemented - # special-case malloc, EXPORTED by default for internal use, but we bake in a - # trivial allocator and warn at runtime if used in ASSERTIONS - is_exception = requested == '_malloc' - in_pre = ('function ' + asstr(requested)) in pre - return is_implemented or is_exception or in_pre - - def get_exported_implemented_functions(all_exported_functions, all_implemented, metadata): funcs = set(metadata['exports']) export_bindings = shared.Settings.EXPORT_BINDINGS