mirror of https://github.com/vacp2p/minime.git
improve getValueAt
This commit is contained in:
parent
3720dc7baa
commit
524cb67110
22
.gas-report
22
.gas-report
|
@ -1,21 +1,21 @@
|
|||
| contracts/MiniMeToken.sol:MiniMeToken contract | | | | | |
|
||||
|------------------------------------------------|-----------------|-------|--------|-------|---------|
|
||||
| Deployment Cost | Deployment Size | | | | |
|
||||
| 2136695 | 12097 | | | | |
|
||||
| 2135687 | 12092 | | | | |
|
||||
| Function Name | min | avg | median | max | # calls |
|
||||
| DOMAIN_SEPARATOR | 387 | 387 | 387 | 387 | 10 |
|
||||
| allowance | 0 | 190 | 0 | 763 | 16 |
|
||||
| approve | 0 | 15064 | 14767 | 31771 | 10 |
|
||||
| approveAndCall | 0 | 31210 | 0 | 93632 | 3 |
|
||||
| balanceOf | 0 | 663 | 0 | 2753 | 67 |
|
||||
| balanceOfAt | 0 | 890 | 0 | 3982 | 78 |
|
||||
| approveAndCall | 0 | 31140 | 0 | 93422 | 3 |
|
||||
| balanceOf | 0 | 622 | 0 | 2753 | 67 |
|
||||
| balanceOfAt | 0 | 830 | 0 | 3766 | 78 |
|
||||
| changeController | 0 | 596 | 0 | 3580 | 6 |
|
||||
| claimTokens | 9559 | 41318 | 57198 | 57198 | 3 |
|
||||
| claimTokens | 9559 | 41038 | 56778 | 56778 | 3 |
|
||||
| controller | 0 | 0 | 0 | 0 | 10 |
|
||||
| decimals | 0 | 0 | 0 | 0 | 10 |
|
||||
| destroyTokens | 2308 | 5207 | 4310 | 9005 | 3 |
|
||||
| destroyTokens | 2098 | 4857 | 3890 | 8585 | 3 |
|
||||
| enableTransfers | 0 | 0 | 0 | 0 | 3 |
|
||||
| generateTokens | 0 | 16512 | 0 | 95730 | 64 |
|
||||
| generateTokens | 0 | 16436 | 0 | 95310 | 64 |
|
||||
| name | 0 | 0 | 0 | 0 | 10 |
|
||||
| nonces | 654 | 1854 | 2654 | 2654 | 5 |
|
||||
| parentSnapShotBlock | 0 | 0 | 0 | 0 | 11 |
|
||||
|
@ -23,10 +23,10 @@
|
|||
| permit | 711 | 39822 | 53956 | 58456 | 10 |
|
||||
| receive | 7960 | 7979 | 7979 | 7998 | 2 |
|
||||
| symbol | 0 | 0 | 0 | 0 | 10 |
|
||||
| totalSupply | 0 | 274 | 0 | 2480 | 23 |
|
||||
| totalSupplyAt | 0 | 859 | 0 | 3614 | 17 |
|
||||
| transfer | 548 | 39300 | 50417 | 93024 | 20 |
|
||||
| transferFrom | 0 | 19676 | 3495 | 66551 | 11 |
|
||||
| totalSupply | 0 | 255 | 0 | 2480 | 23 |
|
||||
| totalSupplyAt | 0 | 797 | 0 | 3398 | 17 |
|
||||
| transfer | 548 | 39069 | 50207 | 92814 | 20 |
|
||||
| transferFrom | 0 | 19588 | 3495 | 66131 | 11 |
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
AllowanceTest:testAllowance() (gas: 42775)
|
||||
AllowanceTest:testAllowanceAlreadySet() (gas: 36905)
|
||||
AllowanceTest:testAllowanceReset() (gas: 46071)
|
||||
AllowanceTest:testApproveAndCall() (gas: 98551)
|
||||
AllowanceTest:testApproveAndCall() (gas: 98341)
|
||||
AllowanceTest:testApproveTransferDisabled() (gas: 7994)
|
||||
AllowanceTest:testDeployment() (gas: 26711)
|
||||
AllowanceTest:testNoAllowance() (gas: 9462)
|
||||
AllowanceTest:testRejectedApproval() (gas: 13683)
|
||||
ClaimTokensTest:testClaimERC20() (gas: 63784)
|
||||
ClaimTokensTest:testClaimERC20() (gas: 63364)
|
||||
ClaimTokensTest:testClaimETH() (gas: 13659)
|
||||
ClaimTokensTest:testClaimSelf() (gas: 61266)
|
||||
ClaimTokensTest:testClaimSelf() (gas: 60846)
|
||||
ClaimTokensTest:testDeployment() (gas: 26595)
|
||||
CreateCloneTokenTest:testCloneFutureSnapshot() (gas: 101242)
|
||||
CreateCloneTokenTest:testCreateCloneToken() (gas: 2175810)
|
||||
CreateCloneTokenTest:testCloneFutureSnapshot() (gas: 101032)
|
||||
CreateCloneTokenTest:testCreateCloneToken() (gas: 2174794)
|
||||
CreateCloneTokenTest:testDeployment() (gas: 26550)
|
||||
CreateCloneTokenTest:testGenerateTokens() (gas: 102016)
|
||||
CreateCloneTokenTest:testGenerateTokens() (gas: 101386)
|
||||
DestroyTokensTest:testDeployment() (gas: 26595)
|
||||
DestroyTokensTest:testDestroyTokens() (gas: 13505)
|
||||
DestroyTokensTest:testDestroyTokensNotEnoughBalance() (gas: 9666)
|
||||
DestroyTokensTest:testDestroyTokensNotEnoughSupply() (gas: 7997)
|
||||
DestroyTokensTest:testDestroyTokens() (gas: 13085)
|
||||
DestroyTokensTest:testDestroyTokensNotEnoughBalance() (gas: 9246)
|
||||
DestroyTokensTest:testDestroyTokensNotEnoughSupply() (gas: 7787)
|
||||
GenerateTokensTest:testDeployment() (gas: 26550)
|
||||
GenerateTokensTest:testGenerateTokens() (gas: 109522)
|
||||
GenerateTokensTest:testGenerateTokensSupplyOverflow() (gas: 3126)
|
||||
|
@ -26,7 +26,7 @@ MiniMeTokenTest:testDeployment() (gas: 26535)
|
|||
ReceiveTest:testAcceptingEther() (gas: 18628)
|
||||
ReceiveTest:testDeployment() (gas: 26595)
|
||||
ReceiveTest:testRejectingEther() (gas: 18691)
|
||||
ReentrancyTest:testAttack() (gas: 229445)
|
||||
ReentrancyTest:testAttack() (gas: 228605)
|
||||
TestPermit:testDeployment() (gas: 26573)
|
||||
TestPermit:testInvalidAllowance() (gas: 84299)
|
||||
TestPermit:testInvalidBalance() (gas: 67380)
|
||||
|
@ -35,21 +35,21 @@ TestPermit:testRevertExpiredPermit() (gas: 27867)
|
|||
TestPermit:testRevertInvalidNonce() (gas: 57221)
|
||||
TestPermit:testRevertInvalidSigner() (gas: 56059)
|
||||
TestPermit:testRevertSignatureReplay() (gas: 96568)
|
||||
TestPermit:testTransferFromLimitedPermit() (gas: 216135)
|
||||
TestPermit:testTransferFromMaxPermit() (gas: 236074)
|
||||
TestPermit:testTransferFromLimitedPermit() (gas: 215505)
|
||||
TestPermit:testTransferFromMaxPermit() (gas: 235444)
|
||||
TestSnapshotReads:testDeployment() (gas: 26550)
|
||||
TestSnapshotReads:testSnapshotReads() (gas: 754393)
|
||||
TestSnapshotReads:testSnapshotReads() (gas: 743821)
|
||||
TransferTest:testDeployment() (gas: 26617)
|
||||
TransferTest:testDoubleTransfer() (gas: 92469)
|
||||
TransferTest:testDoubleTransfer2() (gas: 70622)
|
||||
TransferTest:testDoubleTransfer() (gas: 91839)
|
||||
TransferTest:testDoubleTransfer2() (gas: 69782)
|
||||
TransferTest:testInvalidDestinationTransfer() (gas: 6424)
|
||||
TransferTest:testInvalidDestinationTransfer2() (gas: 6421)
|
||||
TransferTest:testMultipleTransferToSame() (gas: 114699)
|
||||
TransferTest:testMultipleTransferToSame2() (gas: 92896)
|
||||
TransferTest:testRejectedTransfer() (gas: 59943)
|
||||
TransferTest:testTransfer() (gas: 81740)
|
||||
TransferTest:testTransfer2() (gas: 59916)
|
||||
TransferTest:testTransferControllerZero() (gas: 59863)
|
||||
TransferTest:testMultipleTransferToSame() (gas: 114069)
|
||||
TransferTest:testMultipleTransferToSame2() (gas: 92056)
|
||||
TransferTest:testRejectedTransfer() (gas: 59733)
|
||||
TransferTest:testTransfer() (gas: 81530)
|
||||
TransferTest:testTransfer2() (gas: 59496)
|
||||
TransferTest:testTransferControllerZero() (gas: 59653)
|
||||
TransferTest:testTransferDisabled() (gas: 7990)
|
||||
TransferTest:testTransferFromDisabled() (gas: 6526)
|
||||
TransferTest:testTransferNoBalance() (gas: 16949)
|
|
@ -413,17 +413,18 @@ abstract contract MiniMeBase is Controlled, IERC20, IERC20Permit, EIP712, Nonces
|
|||
/// @param _block The block number to retrieve the value at
|
||||
/// @return The number of tokens being queried
|
||||
function getValueAt(Checkpoint[] storage checkpoints, uint256 _block) internal view returns (uint256) {
|
||||
if (checkpoints.length == 0) return 0;
|
||||
uint256 len = checkpoints.length;
|
||||
if (len == 0) return 0;
|
||||
|
||||
// Shortcut for the actual value
|
||||
if (_block >= checkpoints[checkpoints.length - 1].fromBlock) {
|
||||
return checkpoints[checkpoints.length - 1].value;
|
||||
if (_block >= checkpoints[len - 1].fromBlock) {
|
||||
return checkpoints[len - 1].value;
|
||||
}
|
||||
if (_block < checkpoints[0].fromBlock) return 0;
|
||||
|
||||
// Binary search of the value in the array
|
||||
uint256 sMin = 0;
|
||||
uint256 max = checkpoints.length - 1;
|
||||
uint256 max = len - 1;
|
||||
while (max > sMin) {
|
||||
uint256 mid = (max + sMin + 1) / 2;
|
||||
if (checkpoints[mid].fromBlock <= _block) {
|
||||
|
|
Loading…
Reference in New Issue