mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Increase code cost for branching statements.
This commit is contained in:
@@ -63,6 +63,16 @@ void CodeSize::visit(Statement const& _statement)
|
||||
{
|
||||
if (_statement.type() == typeid(FunctionDefinition) && m_ignoreFunctions)
|
||||
return;
|
||||
else if (
|
||||
_statement.type() == typeid(If) ||
|
||||
_statement.type() == typeid(Break) ||
|
||||
_statement.type() == typeid(Continue)
|
||||
)
|
||||
m_size += 2;
|
||||
else if (_statement.type() == typeid(ForLoop))
|
||||
m_size += 3;
|
||||
else if (_statement.type() == typeid(Switch))
|
||||
m_size += 1 + 2 * boost::get<Switch>(_statement).cases.size();
|
||||
else if (!(
|
||||
_statement.type() == typeid(Block) ||
|
||||
_statement.type() == typeid(ExpressionStatement) ||
|
||||
|
||||
@@ -37,6 +37,11 @@ namespace yul
|
||||
* - variable references
|
||||
* - variable declarations (only the right hand side has a cost)
|
||||
* - assignments (only the value has a cost)
|
||||
*
|
||||
* As another exception, each statement incurs and additional cost of one
|
||||
* per jump/branch. This means if, break and continue statements have a cost of 2,
|
||||
* switch statements have a cost of 1 plus the number of cases times two,
|
||||
* and for loops cost 3.
|
||||
*/
|
||||
class CodeSize: public ASTWalker
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user