Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Low - MiniMeToken.sol updateValueAtNow() optimization #138

Open
k4ms opened this issue Jun 18, 2017 · 0 comments
Open

Low - MiniMeToken.sol updateValueAtNow() optimization #138

k4ms opened this issue Jun 18, 2017 · 0 comments

Comments

@k4ms
Copy link

k4ms commented Jun 18, 2017

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);     
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant