diff options
author | chriseth <chris@ethereum.org> | 2018-04-05 16:22:55 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-05-02 23:39:42 +0800 |
commit | ca9fa053b7dc01fe2c5d6c34811c52051f1c77cf (patch) | |
tree | cbc8941d6e9811fb520c774b81c0654176416ba1 /libjulia/optimiser | |
parent | 12b47a6e0b6d8f89301d233b698ef171e4953f65 (diff) | |
download | dexon-solidity-ca9fa053b7dc01fe2c5d6c34811c52051f1c77cf.tar.gz dexon-solidity-ca9fa053b7dc01fe2c5d6c34811c52051f1c77cf.tar.zst dexon-solidity-ca9fa053b7dc01fe2c5d6c34811c52051f1c77cf.zip |
Optimize number of moves.
Diffstat (limited to 'libjulia/optimiser')
-rw-r--r-- | libjulia/optimiser/FullInliner.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/libjulia/optimiser/FullInliner.cpp b/libjulia/optimiser/FullInliner.cpp index 96116ac3..05d70729 100644 --- a/libjulia/optimiser/FullInliner.cpp +++ b/libjulia/optimiser/FullInliner.cpp @@ -92,21 +92,27 @@ void InlineModifier::operator()(ForLoop& _loop) void InlineModifier::operator()(Block& _block) { - // TODO: optimize the number of moves here. + // This is only used if needed to minimize the number of move operations. + vector<Statement> modifiedStatements; for (size_t i = 0; i < _block.statements.size(); ++i) { visit(_block.statements.at(i)); - if (size_t length = m_statementsToPrefix.size()) + if (!m_statementsToPrefix.empty()) { - _block.statements.insert( - _block.statements.begin() + i, - std::make_move_iterator(m_statementsToPrefix.begin()), - std::make_move_iterator(m_statementsToPrefix.end()) - ); - i += length; + if (modifiedStatements.empty()) + std::move( + _block.statements.begin(), + _block.statements.begin() + i, + back_inserter(modifiedStatements) + ); + modifiedStatements += std::move(m_statementsToPrefix); m_statementsToPrefix.clear(); } + if (!modifiedStatements.empty()) + modifiedStatements.emplace_back(std::move(_block.statements[i])); } + if (!modifiedStatements.empty()) + _block.statements = std::move(modifiedStatements); } void InlineModifier::visit(Expression& _expression) |