Merge branch 'master' into typo-fixes

This commit is contained in:
Hadrien Croubois
2025-07-08 09:06:55 +02:00
committed by GitHub
8 changed files with 122 additions and 113 deletions

View File

@ -137,7 +137,7 @@ function at(Bytes32ToBytes32Map storage map, uint256 index) internal view return
}
/**
* @dev Tries to returns the value associated with \`key\`. O(1).
* @dev Tries to return the value associated with \`key\`. O(1).
* Does not revert if \`key\` is not in the map.
*/
function tryGet(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool exists, bytes32 value) {
@ -255,7 +255,7 @@ function at(${name} storage map, uint256 index) internal view returns (${key.typ
}
/**
* @dev Tries to returns the value associated with \`key\`. O(1).
* @dev Tries to return the value associated with \`key\`. O(1).
* Does not revert if \`key\` is not in the map.
*/
function tryGet(${name} storage map, ${key.type} key) internal view returns (bool exists, ${value.type} value) {
@ -275,7 +275,7 @@ function get(${name} storage map, ${key.type} key) internal view returns (${valu
}
/**
* @dev Return the an array containing all the keys
* @dev Returns an array containing all the keys
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
@ -294,7 +294,7 @@ function keys(${name} storage map) internal view returns (${key.type}[] memory)
}
/**
* @dev Return the an array containing a slice of the keys
* @dev Returns an array containing a slice of the keys
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
@ -394,7 +394,7 @@ function at(
}
/**
* @dev Tries to returns the value associated with \`key\`. O(1).
* @dev Tries to return the value associated with \`key\`. O(1).
* Does not revert if \`key\` is not in the map.
*/
function tryGet(

View File

@ -324,12 +324,12 @@ struct ${name} {
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(${name} storage self, ${value.type} memory value) internal returns (bool) {
if (!contains(self, value)) {
self._values.push(value);
function add(${name} storage set, ${value.type} memory value) internal returns (bool) {
if (!contains(set, value)) {
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
self._positions[value] = self._values.length;
set._positions[value] = set._values.length;
return true;
} else {
return false;
@ -342,33 +342,33 @@ function add(${name} storage self, ${value.type} memory value) internal returns
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(${name} storage self, ${value.type} memory value) internal returns (bool) {
function remove(${name} storage set, ${value.type} memory value) internal returns (bool) {
// We cache the value's position to prevent multiple reads from the same storage slot
uint256 position = self._positions[value];
uint256 position = set._positions[value];
if (position != 0) {
// Equivalent to contains(self, value)
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 valueIndex = position - 1;
uint256 lastIndex = self._values.length - 1;
uint256 lastIndex = set._values.length - 1;
if (valueIndex != lastIndex) {
${value.type} memory lastValue = self._values[lastIndex];
${value.type} memory lastValue = set._values[lastIndex];
// Move the lastValue to the index where the value to delete is
self._values[valueIndex] = lastValue;
set._values[valueIndex] = lastValue;
// Update the tracked position of the lastValue (that was just moved)
self._positions[lastValue] = position;
set._positions[lastValue] = position;
}
// Delete the slot where the moved value was stored
self._values.pop();
set._values.pop();
// Delete the tracked position for the deleted slot
delete self._positions[value];
delete set._positions[value];
return true;
} else {
@ -393,15 +393,15 @@ function clear(${name} storage set) internal {
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(${name} storage self, ${value.type} memory value) internal view returns (bool) {
return self._positions[value] != 0;
function contains(${name} storage set, ${value.type} memory value) internal view returns (bool) {
return set._positions[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function length(${name} storage self) internal view returns (uint256) {
return self._values.length;
function length(${name} storage set) internal view returns (uint256) {
return set._values.length;
}
/**
@ -414,8 +414,8 @@ function length(${name} storage self) internal view returns (uint256) {
*
* - \`index\` must be strictly less than {length}.
*/
function at(${name} storage self, uint256 index) internal view returns (${value.type} memory) {
return self._values[index];
function at(${name} storage set, uint256 index) internal view returns (${value.type} memory) {
return set._values[index];
}
/**
@ -426,8 +426,8 @@ function at(${name} storage self, uint256 index) internal view returns (${value.
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(${name} storage self) internal view returns (${value.type}[] memory) {
return self._values;
function values(${name} storage set) internal view returns (${value.type}[] memory) {
return set._values;
}
/**