diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-03-22 18:06:29 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-03-22 18:06:29 -0700 |
commit | c5a6210d4a60d194f6ab690f6f1206c6076e222d (patch) | |
tree | d7e7af4aad70cbdea6d117a34739d4d12c35697d /src/wasm-binary.h | |
parent | 468e0dde46724e2a40fa311a878d0d50cac8f831 (diff) | |
parent | b4c0c719e14327df55a2b70f92475e89ce1e055e (diff) | |
download | binaryen-c5a6210d4a60d194f6ab690f6f1206c6076e222d.tar.gz binaryen-c5a6210d4a60d194f6ab690f6f1206c6076e222d.tar.bz2 binaryen-c5a6210d4a60d194f6ab690f6f1206c6076e222d.zip |
Merge pull request #251 from mbebenita/opt-wasm-as
Optimize function => index mapping.
Diffstat (limited to 'src/wasm-binary.h')
-rw-r--r-- | src/wasm-binary.h | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 21438f616..6782eec21 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -670,19 +670,30 @@ public: finishSection(start); } + std::map<Name, uint32_t> mappedImports; // name of the Import => index uint32_t getImportIndex(Name name) { - // TODO: optimize - for (size_t i = 0; i < wasm->imports.size(); i++) { - if (wasm->imports[i]->name == name) return i; - } - abort(); - } + if (!mappedImports.size()) { + // Create name => index mapping. + for (size_t i = 0; i < wasm->imports.size(); i++) { + assert(mappedImports.count(wasm->imports[i]->name) == 0); + mappedImports[wasm->imports[i]->name] = i; + } + } + assert(mappedImports.count(name)); + return mappedImports[name]; + } + + std::map<Name, uint32_t> mappedFunctions; // name of the Function => index uint32_t getFunctionIndex(Name name) { - // TODO: optimize - for (size_t i = 0; i < wasm->functions.size(); i++) { - if (wasm->functions[i]->name == name) return i; - } - abort(); + if (!mappedFunctions.size()) { + // Create name => index mapping. + for (size_t i = 0; i < wasm->functions.size(); i++) { + assert(mappedFunctions.count(wasm->functions[i]->name) == 0); + mappedFunctions[wasm->functions[i]->name] = i; + } + } + assert(mappedFunctions.count(name)); + return mappedFunctions[name]; } void writeFunctionTable() { |