diff options
author | Max Graey <maxgraey@gmail.com> | 2021-09-23 01:05:27 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-22 22:05:27 +0000 |
commit | b6820540c8055dd7720ff369c7c0b6ebb34391f0 (patch) | |
tree | 3fa47686331de4a9f32528ada01a94394ed308f0 /src | |
parent | c50ab818ee6643b903ad3727f3fe10235fc801ff (diff) | |
download | binaryen-b6820540c8055dd7720ff369c7c0b6ebb34391f0.tar.gz binaryen-b6820540c8055dd7720ff369c7c0b6ebb34391f0.tar.bz2 binaryen-b6820540c8055dd7720ff369c7c0b6ebb34391f0.zip |
[Refactoring] Code reusage in spliceIntoBlock (#4174)
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/ExpressionManipulator.cpp | 12 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 2 |
2 files changed, 3 insertions, 11 deletions
diff --git a/src/ir/ExpressionManipulator.cpp b/src/ir/ExpressionManipulator.cpp index 535aa51c3..0bb94a66d 100644 --- a/src/ir/ExpressionManipulator.cpp +++ b/src/ir/ExpressionManipulator.cpp @@ -114,17 +114,7 @@ flexibleCopy(Expression* original, Module& wasm, CustomCopier custom) { // Splice an item into the middle of a block's list void spliceIntoBlock(Block* block, Index index, Expression* add) { - auto& list = block->list; - if (index == list.size()) { - list.push_back(add); // simple append - } else { - // we need to make room - list.push_back(nullptr); - for (Index i = list.size() - 1; i > index; i--) { - list[i] = list[i - 1]; - } - list[index] = add; - } + block->list.insertAt(index, add); block->finalize(block->type); } diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index 45137fffe..0f1017e00 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -821,6 +821,7 @@ void Try::finalize() { // If none of the component bodies' type is a supertype of the others, assume // the current type is already correct. TODO: Calculate a proper LUB. std::unordered_set<Type> types{body->type}; + types.reserve(catchBodies.size()); for (auto catchBody : catchBodies) { types.insert(catchBody->type); } @@ -844,6 +845,7 @@ void Rethrow::finalize() { type = Type::unreachable; } void TupleMake::finalize() { std::vector<Type> types; + types.reserve(operands.size()); for (auto* op : operands) { if (op->type == Type::unreachable) { type = Type::unreachable; |