diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2020-11-19 20:59:14 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-19 20:59:14 -0800 |
commit | de5e7365957b3eaf0d9aa05eea4ee759efb67ca4 (patch) | |
tree | 397149ae1909c35fa6851a87c289ec5427f647b2 /src/wasm/wasm-binary.cpp | |
parent | d0bc3811f00fe90762a9bee19bf354f780704ce5 (diff) | |
download | binaryen-de5e7365957b3eaf0d9aa05eea4ee759efb67ca4.tar.gz binaryen-de5e7365957b3eaf0d9aa05eea4ee759efb67ca4.tar.bz2 binaryen-de5e7365957b3eaf0d9aa05eea4ee759efb67ca4.zip |
[wasm-builder] Construct module elements as unique_ptrs (#3391)
When Functions, Globals, Events, and Exports are added to a module, if they are
not already in std::unique_ptrs, they are wrapped in a new std::unique_ptr owned
by the Module. This adds an extra layer of indirection when accessing those
elements that can be avoided by allocating those elements as std::unique_ptrs.
This PR updates wasm-builder to allocate module elements via std::make_unique
rather than `new`. In the future, we should remove the raw pointer versions of
Module::add* to encourage using std::unique_ptrs more broadly.
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 1a5c8a0f4..b343c6caf 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1474,11 +1474,11 @@ void WasmBinaryBuilder::readImports() { throwError("invalid function index " + std::to_string(index) + " / " + std::to_string(signatures.size())); } - auto* curr = builder.makeFunction(name, signatures[index], {}); + auto curr = builder.makeFunction(name, signatures[index], {}); curr->module = module; curr->base = base; - wasm.addFunction(curr); - functionImports.push_back(curr); + functionImports.push_back(curr.get()); + wasm.addFunction(std::move(curr)); break; } case ExternalKind::Table: { @@ -1524,15 +1524,15 @@ void WasmBinaryBuilder::readImports() { Name name(std::string("gimport$") + std::to_string(globalCounter++)); auto type = getConcreteType(); auto mutable_ = getU32LEB(); - auto* curr = + auto curr = builder.makeGlobal(name, type, nullptr, mutable_ ? Builder::Mutable : Builder::Immutable); curr->module = module; curr->base = base; - wasm.addGlobal(curr); - globalImports.push_back(curr); + globalImports.push_back(curr.get()); + wasm.addGlobal(std::move(curr)); break; } case ExternalKind::Event: { @@ -1543,10 +1543,10 @@ void WasmBinaryBuilder::readImports() { throwError("invalid event index " + std::to_string(index) + " / " + std::to_string(signatures.size())); } - auto* curr = builder.makeEvent(name, attribute, signatures[index]); + auto curr = builder.makeEvent(name, attribute, signatures[index]); curr->module = module; curr->base = base; - wasm.addEvent(curr); + wasm.addEvent(std::move(curr)); break; } default: { @@ -2065,8 +2065,8 @@ void WasmBinaryBuilder::processNames() { for (auto* func : functions) { wasm.addFunction(func); } - for (auto* global : globals) { - wasm.addGlobal(global); + for (auto& global : globals) { + wasm.addGlobal(std::move(global)); } // now that we have names, apply things @@ -3123,7 +3123,7 @@ void WasmBinaryBuilder::visitGlobalGet(GlobalGet* curr) { if (adjustedIndex >= globals.size()) { throwError("invalid global index"); } - auto* glob = globals[adjustedIndex]; + auto& glob = globals[adjustedIndex]; curr->name = glob->name; curr->type = glob->type; } |