Skip to content

Commit 972cc6f

Browse files
authored
[NFC] Simplify binary reading logic for data segments (#4990)
Similar to #4969 but for data segments.
1 parent 8e1abd1 commit 972cc6f

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

src/wasm-binary.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,9 +1529,6 @@ class WasmBinaryBuilder {
15291529
// at index i we have all references to the memory i
15301530
std::map<Index, std::vector<wasm::Name*>> memoryRefs;
15311531

1532-
// we store data here after being read from binary, before we know their names
1533-
std::vector<std::unique_ptr<DataSegment>> dataSegments;
1534-
15351532
// at index i we have all refs to the global i
15361533
std::map<Index, std::vector<Name*>> globalRefs;
15371534

src/wasm/wasm-binary.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2971,15 +2971,12 @@ Expression* WasmBinaryBuilder::popTypedExpression(Type type) {
29712971
}
29722972

29732973
void WasmBinaryBuilder::validateBinary() {
2974-
if (hasDataCount && dataSegments.size() != dataCount) {
2974+
if (hasDataCount && wasm.dataSegments.size() != dataCount) {
29752975
throwError("Number of segments does not agree with DataCount section");
29762976
}
29772977
}
29782978

29792979
void WasmBinaryBuilder::processNames() {
2980-
for (auto& segment : dataSegments) {
2981-
wasm.addDataSegment(std::move(segment));
2982-
}
29832980
// now that we have names, apply things
29842981

29852982
if (startIndex != static_cast<Index>(-1)) {
@@ -3072,7 +3069,7 @@ void WasmBinaryBuilder::readDataSegments() {
30723069
auto size = getU32LEB();
30733070
auto data = getByteView(size);
30743071
curr->data = {data.first, data.second};
3075-
dataSegments.push_back(std::move(curr));
3072+
wasm.addDataSegment(std::move(curr));
30763073
}
30773074
}
30783075

@@ -3398,8 +3395,8 @@ void WasmBinaryBuilder::readNames(size_t payloadLen) {
33983395
auto index = getU32LEB();
33993396
auto rawName = getInlineString();
34003397
auto name = processor.process(rawName);
3401-
if (index < dataSegments.size()) {
3402-
dataSegments[i]->setExplicitName(name);
3398+
if (index < wasm.dataSegments.size()) {
3399+
wasm.dataSegments[i]->setExplicitName(name);
34033400
} else {
34043401
std::cerr << "warning: data index out of bounds in name section, "
34053402
"data subsection: "

0 commit comments

Comments
 (0)