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 7741735
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions contracts/utils/EnumerableSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +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 {
Expand Down

0 comments on commit 7741735

Please sign in to comment.