mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Performance: Replace string by special single-copy YulString class.
This commit is contained in:
@@ -38,9 +38,9 @@ using namespace dev::yul;
|
||||
|
||||
void DataFlowAnalyzer::operator()(Assignment& _assignment)
|
||||
{
|
||||
set<string> names;
|
||||
set<YulString> names;
|
||||
for (auto const& var: _assignment.variableNames)
|
||||
names.insert(var.name);
|
||||
names.emplace(var.name);
|
||||
assertThrow(_assignment.value, OptimizerException, "");
|
||||
visit(*_assignment.value);
|
||||
handleAssignment(names, _assignment.value.get());
|
||||
@@ -48,9 +48,9 @@ void DataFlowAnalyzer::operator()(Assignment& _assignment)
|
||||
|
||||
void DataFlowAnalyzer::operator()(VariableDeclaration& _varDecl)
|
||||
{
|
||||
set<string> names;
|
||||
set<YulString> names;
|
||||
for (auto const& var: _varDecl.variables)
|
||||
names.insert(var.name);
|
||||
names.emplace(var.name);
|
||||
m_variableScopes.back().variables += names;
|
||||
if (_varDecl.value)
|
||||
visit(*_varDecl.value);
|
||||
@@ -69,7 +69,7 @@ void DataFlowAnalyzer::operator()(If& _if)
|
||||
void DataFlowAnalyzer::operator()(Switch& _switch)
|
||||
{
|
||||
visit(*_switch.expression);
|
||||
set<string> assignedVariables;
|
||||
set<YulString> assignedVariables;
|
||||
for (auto& _case: _switch.cases)
|
||||
{
|
||||
(*this)(_case.body);
|
||||
@@ -86,9 +86,9 @@ void DataFlowAnalyzer::operator()(FunctionDefinition& _fun)
|
||||
{
|
||||
pushScope(true);
|
||||
for (auto const& parameter: _fun.parameters)
|
||||
m_variableScopes.back().variables.insert(parameter.name);
|
||||
m_variableScopes.back().variables.emplace(parameter.name);
|
||||
for (auto const& var: _fun.returnVariables)
|
||||
m_variableScopes.back().variables.insert(var.name);
|
||||
m_variableScopes.back().variables.emplace(var.name);
|
||||
ASTModifier::operator()(_fun);
|
||||
popScope();
|
||||
}
|
||||
@@ -122,7 +122,7 @@ void DataFlowAnalyzer::operator()(Block& _block)
|
||||
assertThrow(numScopes == m_variableScopes.size(), OptimizerException, "");
|
||||
}
|
||||
|
||||
void DataFlowAnalyzer::handleAssignment(set<string> const& _variables, Expression* _value)
|
||||
void DataFlowAnalyzer::handleAssignment(set<YulString> const& _variables, Expression* _value)
|
||||
{
|
||||
clearValues(_variables);
|
||||
|
||||
@@ -131,7 +131,7 @@ void DataFlowAnalyzer::handleAssignment(set<string> const& _variables, Expressio
|
||||
movableChecker.visit(*_value);
|
||||
if (_variables.size() == 1)
|
||||
{
|
||||
string const& name = *_variables.begin();
|
||||
YulString name = *_variables.begin();
|
||||
// Expression has to be movable and cannot contain a reference
|
||||
// to the variable that will be assigned to.
|
||||
if (_value && movableChecker.movable() && !movableChecker.referencedVariables().count(name))
|
||||
@@ -143,7 +143,7 @@ void DataFlowAnalyzer::handleAssignment(set<string> const& _variables, Expressio
|
||||
{
|
||||
m_references[name] = referencedVariables;
|
||||
for (auto const& ref: referencedVariables)
|
||||
m_referencedBy[ref].insert(name);
|
||||
m_referencedBy[ref].emplace(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ void DataFlowAnalyzer::popScope()
|
||||
m_variableScopes.pop_back();
|
||||
}
|
||||
|
||||
void DataFlowAnalyzer::clearValues(set<string> _variables)
|
||||
void DataFlowAnalyzer::clearValues(set<YulString> _variables)
|
||||
{
|
||||
// All variables that reference variables to be cleared also have to be
|
||||
// cleared, but not recursively, since only the value of the original
|
||||
@@ -176,7 +176,7 @@ void DataFlowAnalyzer::clearValues(set<string> _variables)
|
||||
// Clear variables that reference variables to be cleared.
|
||||
for (auto const& name: _variables)
|
||||
for (auto const& ref: m_referencedBy[name])
|
||||
_variables.insert(ref);
|
||||
_variables.emplace(ref);
|
||||
|
||||
// Clear the value and update the reference relation.
|
||||
for (auto const& name: _variables)
|
||||
@@ -189,7 +189,7 @@ void DataFlowAnalyzer::clearValues(set<string> _variables)
|
||||
}
|
||||
}
|
||||
|
||||
bool DataFlowAnalyzer::inScope(string const& _variableName) const
|
||||
bool DataFlowAnalyzer::inScope(YulString _variableName) const
|
||||
{
|
||||
for (auto const& scope: m_variableScopes | boost::adaptors::reversed)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user