From 05c210772af9f24f23ddc7afda0ecae98b52e456 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Fri, 17 May 2019 09:41:22 +0200 Subject: [PATCH] Make use of make_vector where possible. --- libyul/optimiser/ControlFlowSimplifier.cpp | 36 ++++++---------- libyul/optimiser/SSAReverser.cpp | 50 +++++++++++----------- libyul/optimiser/StructuralSimplifier.cpp | 8 ++-- 3 files changed, 40 insertions(+), 54 deletions(-) diff --git a/libyul/optimiser/ControlFlowSimplifier.cpp b/libyul/optimiser/ControlFlowSimplifier.cpp index a3b2f4f37..46d5b5bc4 100644 --- a/libyul/optimiser/ControlFlowSimplifier.cpp +++ b/libyul/optimiser/ControlFlowSimplifier.cpp @@ -72,11 +72,7 @@ OptionalStatements reduceNoCaseSwitch(Switch& _switchStmt) auto loc = locationOf(*_switchStmt.expression); - OptionalStatements s = vector{}; - - s->emplace_back(makePopExpressionStatement(loc, std::move(*_switchStmt.expression))); - - return s; + return make_vector(makePopExpressionStatement(loc, std::move(*_switchStmt.expression))); } OptionalStatements reduceSingleCaseSwitch(Switch& _switchStmt) @@ -86,26 +82,20 @@ OptionalStatements reduceSingleCaseSwitch(Switch& _switchStmt) auto& switchCase = _switchStmt.cases.front(); auto loc = locationOf(*_switchStmt.expression); if (switchCase.value) - { - OptionalStatements s = vector{}; - s->emplace_back(If{ - std::move(_switchStmt.location), - make_unique(FunctionalInstruction{ - std::move(loc), - dev::eth::Instruction::EQ, - {std::move(*switchCase.value), std::move(*_switchStmt.expression)} - }), - std::move(switchCase.body) + return make_vector(If{ + std::move(_switchStmt.location), + make_unique(FunctionalInstruction{ + std::move(loc), + dev::eth::Instruction::EQ, + {std::move(*switchCase.value), std::move(*_switchStmt.expression)} + }), + std::move(switchCase.body) }); - return s; - } else - { - OptionalStatements s = vector{}; - s->emplace_back(makePopExpressionStatement(loc, std::move(*_switchStmt.expression))); - s->emplace_back(std::move(switchCase.body)); - return s; - } + return make_vector( + makePopExpressionStatement(loc, std::move(*_switchStmt.expression)), + std::move(switchCase.body) + ); } } diff --git a/libyul/optimiser/SSAReverser.cpp b/libyul/optimiser/SSAReverser.cpp index c11af9142..a9a49fdb6 100644 --- a/libyul/optimiser/SSAReverser.cpp +++ b/libyul/optimiser/SSAReverser.cpp @@ -56,20 +56,18 @@ void SSAReverser::operator()(Block& _block) identifier && identifier->name == varDecl->variables.front().name ) - { - vector result; - result.emplace_back(Assignment{ - std::move(assignment->location), - assignment->variableNames, - std::move(varDecl->value) - }); - result.emplace_back(VariableDeclaration{ - std::move(varDecl->location), - std::move(varDecl->variables), - std::make_unique(std::move(assignment->variableNames.front())) - }); - return { std::move(result) }; - } + return make_vector( + Assignment{ + std::move(assignment->location), + assignment->variableNames, + std::move(varDecl->value) + }, + VariableDeclaration{ + std::move(varDecl->location), + std::move(varDecl->variables), + std::make_unique(std::move(assignment->variableNames.front())) + } + ); } // Replaces // let a_1 := E @@ -89,22 +87,22 @@ void SSAReverser::operator()(Block& _block) ) ) { - vector result; auto varIdentifier2 = std::make_unique(Identifier{ varDecl2->variables.front().location, varDecl2->variables.front().name }); - result.emplace_back(VariableDeclaration{ - std::move(varDecl2->location), - std::move(varDecl2->variables), - std::move(varDecl->value) - }); - result.emplace_back(VariableDeclaration{ - std::move(varDecl->location), - std::move(varDecl->variables), - std::move(varIdentifier2) - }); - return { std::move(result) }; + return make_vector( + VariableDeclaration{ + std::move(varDecl2->location), + std::move(varDecl2->variables), + std::move(varDecl->value) + }, + VariableDeclaration{ + std::move(varDecl->location), + std::move(varDecl->variables), + std::move(varIdentifier2) + } + ); } } diff --git a/libyul/optimiser/StructuralSimplifier.cpp b/libyul/optimiser/StructuralSimplifier.cpp index 322dbe48e..867f670ca 100644 --- a/libyul/optimiser/StructuralSimplifier.cpp +++ b/libyul/optimiser/StructuralSimplifier.cpp @@ -51,12 +51,10 @@ OptionalStatements replaceConstArgSwitch(Switch& _switchStmt, u256 const& _const if (!matchingCaseBlock && defaultCase) matchingCaseBlock = &defaultCase->body; - OptionalStatements s = vector{}; - if (matchingCaseBlock) - s->emplace_back(std::move(*matchingCaseBlock)); - - return s; + return make_vector(std::move(*matchingCaseBlock)); + else + return {{}}; } }