mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Adding vardecl optimization for boolean types
This commit is contained in:
committed by
chriseth
parent
e75cace78d
commit
a52c9af5b9
@@ -20,6 +20,7 @@
|
||||
|
||||
#include <libsolutil/CommonData.h>
|
||||
#include <libsolutil/Visitor.h>
|
||||
#include <libyul/Dialect.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace solidity;
|
||||
@@ -32,14 +33,14 @@ void VarDeclInitializer::operator()(Block& _block)
|
||||
using OptionalStatements = std::optional<vector<Statement>>;
|
||||
util::GenericVisitor visitor{
|
||||
util::VisitorFallback<OptionalStatements>{},
|
||||
[](VariableDeclaration& _varDecl) -> OptionalStatements
|
||||
[this](VariableDeclaration& _varDecl) -> OptionalStatements
|
||||
{
|
||||
if (_varDecl.value)
|
||||
return {};
|
||||
Literal zero{{}, LiteralKind::Number, YulString{"0"}, {}};
|
||||
|
||||
if (_varDecl.variables.size() == 1)
|
||||
{
|
||||
_varDecl.value = make_unique<Expression>(std::move(zero));
|
||||
_varDecl.value = make_unique<Expression>(m_dialect.zeroLiteralForType(_varDecl.variables.front().type));
|
||||
return {};
|
||||
}
|
||||
else
|
||||
@@ -47,7 +48,10 @@ void VarDeclInitializer::operator()(Block& _block)
|
||||
OptionalStatements ret{vector<Statement>{}};
|
||||
langutil::SourceLocation loc{std::move(_varDecl.location)};
|
||||
for (auto& var: _varDecl.variables)
|
||||
ret->emplace_back(VariableDeclaration{loc, {std::move(var)}, make_unique<Expression>(zero)});
|
||||
{
|
||||
unique_ptr<Expression> expr = make_unique<Expression >(m_dialect.zeroLiteralForType(var.type));
|
||||
ret->emplace_back(VariableDeclaration{loc, {std::move(var)}, std::move(expr)});
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user