From 165e6f19489786c9c6abfcc9bdc8f2815d807935 Mon Sep 17 00:00:00 2001 From: William Morriss Date: Tue, 20 Apr 2021 12:51:26 -0700 Subject: [PATCH] EnumerableSet: Remove Boundary Check in _at (#2606) * remove boundary check * fix tests for EnumerableSet "index out of bound" * Changelog Co-authored-by: Hadrien Croubois --- CHANGELOG.md | 1 + contracts/utils/structs/EnumerableSet.sol | 1 - test/utils/structs/EnumerableSet.behavior.js | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b647cabe134..3b7923b9d10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased * Enumerables: Improve gas cost of removal in `EnumerableSet` and `EnumerableMap`. + * Enumerables: Improve gas cost of lookup in `EnumerableSet` and `EnumerableMap`. ## Unreleased diff --git a/contracts/utils/structs/EnumerableSet.sol b/contracts/utils/structs/EnumerableSet.sol index 0b9903beebb..ca1dac1590a 100644 --- a/contracts/utils/structs/EnumerableSet.sol +++ b/contracts/utils/structs/EnumerableSet.sol @@ -127,7 +127,6 @@ library EnumerableSet { * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { - require(set._values.length > index, "EnumerableSet: index out of bounds"); return set._values[index]; } diff --git a/test/utils/structs/EnumerableSet.behavior.js b/test/utils/structs/EnumerableSet.behavior.js index 985071a27e3..be3f52a5e5a 100644 --- a/test/utils/structs/EnumerableSet.behavior.js +++ b/test/utils/structs/EnumerableSet.behavior.js @@ -51,7 +51,7 @@ function shouldBehaveLikeSet (valueA, valueB, valueC) { describe('at', function () { it('reverts when retrieving non-existent elements', async function () { - await expectRevert(this.set.at(0), 'EnumerableSet: index out of bounds'); + await expectRevert.unspecified(this.set.at(0)); }); });