|
@@ -81,15 +81,14 @@ library EnumerableSet {
|
|
uint256 toDeleteIndex = valueIndex - 1;
|
|
uint256 toDeleteIndex = valueIndex - 1;
|
|
uint256 lastIndex = set._values.length - 1;
|
|
uint256 lastIndex = set._values.length - 1;
|
|
|
|
|
|
- // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs
|
|
|
|
- // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.
|
|
|
|
-
|
|
|
|
- bytes32 lastvalue = set._values[lastIndex];
|
|
|
|
-
|
|
|
|
- // Move the last value to the index where the value to delete is
|
|
|
|
- set._values[toDeleteIndex] = lastvalue;
|
|
|
|
- // Update the index for the moved value
|
|
|
|
- set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex
|
|
|
|
|
|
+ if (lastIndex != toDeleteIndex) {
|
|
|
|
+ bytes32 lastvalue = set._values[lastIndex];
|
|
|
|
+
|
|
|
|
+ // Move the last value to the index where the value to delete is
|
|
|
|
+ set._values[toDeleteIndex] = lastvalue;
|
|
|
|
+ // Update the index for the moved value
|
|
|
|
+ set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex
|
|
|
|
+ }
|
|
|
|
|
|
// Delete the slot where the moved value was stored
|
|
// Delete the slot where the moved value was stored
|
|
set._values.pop();
|
|
set._values.pop();
|