Permalink
Browse files

improve mum performance and reduce gas cost

  • Loading branch information...
emn178 committed Oct 30, 2017
1 parent 39d6c92 commit 5ad07e1892a08e8485d0ba6752eeb67fbd4182b2
Showing with 4 additions and 1 deletion.
  1. +4 −1 contracts/math/SafeMath.sol
@@ -7,8 +7,11 @@ pragma solidity ^0.4.11;
*/
library SafeMath {
function mul(uint256 a, uint256 b) internal constant returns (uint256) {
if (a == 0) {

This comment has been minimized.

@lastperson

lastperson Jan 4, 2018

Contributor

@emn178 why only checking a for 0? Why not if (a == 0 || b == 0) { ?

This comment has been minimized.

@lastperson

lastperson Jan 4, 2018

Contributor

I assume that is because there is only a division for a, and it was not meant to optimize the cases when b == 0 because it a rare case.

return 0;
}
uint256 c = a * b;
assert(a == 0 || c / a == b);
assert(c / a == b);
return c;
}

0 comments on commit 5ad07e1

Please sign in to comment.