From 972cc6f39cb903834be6066c33356f77fc41bc26 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 31 Aug 2022 09:10:22 -0700 Subject: [NFC] Simplify binary reading logic for data segments (#4990) Similar to #4969 but for data segments. --- src/wasm-binary.h | 3 --- src/wasm/wasm-binary.cpp | 11 ++++------- 2 files changed, 4 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 2359d53bf..ab55b6f50 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1529,9 +1529,6 @@ public: // at index i we have all references to the memory i std::map> memoryRefs; - // we store data here after being read from binary, before we know their names - std::vector> dataSegments; - // at index i we have all refs to the global i std::map> globalRefs; diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index baff0d83f..03ae5ce5a 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -2971,15 +2971,12 @@ Expression* WasmBinaryBuilder::popTypedExpression(Type type) { } void WasmBinaryBuilder::validateBinary() { - if (hasDataCount && dataSegments.size() != dataCount) { + if (hasDataCount && wasm.dataSegments.size() != dataCount) { throwError("Number of segments does not agree with DataCount section"); } } void WasmBinaryBuilder::processNames() { - for (auto& segment : dataSegments) { - wasm.addDataSegment(std::move(segment)); - } // now that we have names, apply things if (startIndex != static_cast(-1)) { @@ -3072,7 +3069,7 @@ void WasmBinaryBuilder::readDataSegments() { auto size = getU32LEB(); auto data = getByteView(size); curr->data = {data.first, data.second}; - dataSegments.push_back(std::move(curr)); + wasm.addDataSegment(std::move(curr)); } } @@ -3398,8 +3395,8 @@ void WasmBinaryBuilder::readNames(size_t payloadLen) { auto index = getU32LEB(); auto rawName = getInlineString(); auto name = processor.process(rawName); - if (index < dataSegments.size()) { - dataSegments[i]->setExplicitName(name); + if (index < wasm.dataSegments.size()) { + wasm.dataSegments[i]->setExplicitName(name); } else { std::cerr << "warning: data index out of bounds in name section, " "data subsection: " -- cgit v1.2.3