status-network-token
status-network-token copied to clipboard
Low - MiniMeToken.sol updateValueAtNow() optimization
trafficstars
In 'MiniMeToken.sol' the updateValueAtNow() function adds levels of complexity than can be avoided:
- calling push() is cheaper than increasing the checkpoint length and assigning value to the struct
- too many local variables are used
Proposed implementation:
function updateValueAtNow(Checkpoint[] storage checkpoints, uint _value) internal {
if ((checkpoints.length == 0)
|| (checkpoints[checkpoints.length -1].fromBlock < getBlockNumber())) {
checkpoints.push(Checkpoint({
fromBlock: uint128(getBlockNumber()),
value: uint128(_value)
}));
} else {
checkpoints[checkpoints.length-1].value = uint128(_value);
}
}