diff options
author | Alon Zakai <alonzakai@gmail.com> | 2017-05-04 13:28:58 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-04 13:28:58 -0700 |
commit | 5af21d6692c130a69af6bc96e74bed9717e4d4a3 (patch) | |
tree | e5c72b7d485a7cccc861b55ce3fb2f5e4b3d90bb /src | |
parent | d0f4e932110812a35cfee9d213e9cd0ce610011a (diff) | |
download | binaryen-5af21d6692c130a69af6bc96e74bed9717e4d4a3.tar.gz binaryen-5af21d6692c130a69af6bc96e74bed9717e4d4a3.tar.bz2 binaryen-5af21d6692c130a69af6bc96e74bed9717e4d4a3.zip |
optimize duplication checks in binary format reading (#995)
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index a9ec63ccd..159099a16 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -945,13 +945,12 @@ void WasmBinaryBuilder::read() { auto oldPos = pos; - // almost no sections can appear more than once - if (seenSections.count(BinaryConsts::Section(sectionCode)) > 0) { - if (sectionCode != BinaryConsts::Section::User && sectionCode != BinaryConsts::Section::Code) { + // note the section in the list of seen sections, as almost no sections can appear more than once, + // and verify those that shouldn't do not. + if (sectionCode != BinaryConsts::Section::User && sectionCode != BinaryConsts::Section::Code) { + if (!seenSections.insert(BinaryConsts::Section(sectionCode)).second) { throw ParseException("section seen more than once: " + std::to_string(sectionCode)); } - } else { - seenSections.insert(BinaryConsts::Section(sectionCode)); } switch (sectionCode) { @@ -1609,10 +1608,9 @@ void WasmBinaryBuilder::readNames(size_t payloadLen) { // disallow duplicate names std::set<Name> functionNames; for (auto* func : functions) { - if (functionNames.count(func->name) > 0) { + if (!functionNames.insert(func->name).second) { throw ParseException("duplicate function name: " + std::string(func->name.str)); } - functionNames.insert(func->name); } if (pos != subsectionPos + subsectionSize) { throw ParseException("bad names subsection position change"); |