You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
contractImmutableCached {
uint256public immutable one =1;
function two() publicreturns (uint256result) {
result = one + one;
}
}
yields:
### <a name="GAS-1"></a>[GAS-1] State variables should be cached in stack variables rather than re-reading them from storage
The instances below point to the second+ access of a state variable within a function. Caching of a state variable replaces each Gwarmaccess (100 gas) with a much cheaper stack read. Other less obvious fixes/optimizations include having local memory caches of state variable structs, or having local caches of state variable contracts/addresses.
*Saves 100 gas per instance*
*Instances (1)*:
``solidity
File: lol.sol
7: result = one + one;
``
This is a weird issue, because depending on how code is expressed it may not trigger, e.g. changing
result = one + one;
into
return one + one;
fixes the warning.
The text was updated successfully, but these errors were encountered:
For example:
yields:
This is a weird issue, because depending on how code is expressed it may not trigger, e.g. changing
into
fixes the warning.
The text was updated successfully, but these errors were encountered: