Skip to content

Commit

Permalink
assembly isn't more efficient for EnumerableSet.add
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Feb 9, 2021
1 parent 7402f58 commit de4b0ae
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions contracts/utils/EnumerableSet.sol
Expand Up @@ -53,21 +53,10 @@ library EnumerableSet {
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {

uint256 last;
assembly {
let p := sload(0x40)
mstore(p, set.slot)
let blk := keccak256(p, 0x20)
// push new value
last := sload(set.slot)
sstore(add(blk, last), value)
// update array length
last := add(last, 1)
sstore(set.slot, last)
}
set._indexes[value] = last;

set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
Expand Down

0 comments on commit de4b0ae

Please sign in to comment.