Consistently name multiple returned values (#5177)
This commit is contained in:
@ -41,7 +41,11 @@ struct ${opts.checkpointTypeName} {
|
||||
* IMPORTANT: Never accept \`key\` as a user input, since an arbitrary \`type(${opts.keyTypeName}).max\` key set will disable the
|
||||
* library.
|
||||
*/
|
||||
function push(${opts.historyTypeName} storage self, ${opts.keyTypeName} key, ${opts.valueTypeName} value) internal returns (${opts.valueTypeName}, ${opts.valueTypeName}) {
|
||||
function push(
|
||||
${opts.historyTypeName} storage self,
|
||||
${opts.keyTypeName} key,
|
||||
${opts.valueTypeName} value
|
||||
) internal returns (${opts.valueTypeName} oldValue, ${opts.valueTypeName} newValue) {
|
||||
return _insert(self.${opts.checkpointFieldName}, key, value);
|
||||
}
|
||||
|
||||
@ -132,7 +136,11 @@ function at(${opts.historyTypeName} storage self, uint32 pos) internal view retu
|
||||
* @dev Pushes a (\`key\`, \`value\`) pair into an ordered list of checkpoints, either by inserting a new checkpoint,
|
||||
* or by updating the last one.
|
||||
*/
|
||||
function _insert(${opts.checkpointTypeName}[] storage self, ${opts.keyTypeName} key, ${opts.valueTypeName} value) private returns (${opts.valueTypeName}, ${opts.valueTypeName}) {
|
||||
function _insert(
|
||||
${opts.checkpointTypeName}[] storage self,
|
||||
${opts.keyTypeName} key,
|
||||
${opts.valueTypeName} value
|
||||
) private returns (${opts.valueTypeName} oldValue, ${opts.valueTypeName} newValue) {
|
||||
uint256 pos = self.length;
|
||||
|
||||
if (pos > 0) {
|
||||
|
||||
@ -117,21 +117,21 @@ function length(Bytes32ToBytes32Map storage map) internal view returns (uint256)
|
||||
*
|
||||
* - \`index\` must be strictly less than {length}.
|
||||
*/
|
||||
function at(Bytes32ToBytes32Map storage map, uint256 index) internal view returns (bytes32, bytes32) {
|
||||
bytes32 key = map._keys.at(index);
|
||||
return (key, map._values[key]);
|
||||
function at(Bytes32ToBytes32Map storage map, uint256 index) internal view returns (bytes32 key, bytes32 value) {
|
||||
bytes32 atKey = map._keys.at(index);
|
||||
return (atKey, map._values[atKey]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Tries to returns 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, bytes32) {
|
||||
bytes32 value = map._values[key];
|
||||
if (value == bytes32(0)) {
|
||||
function tryGet(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool exists, bytes32 value) {
|
||||
bytes32 val = map._values[key];
|
||||
if (val == bytes32(0)) {
|
||||
return (contains(map, key), bytes32(0));
|
||||
} else {
|
||||
return (true, value);
|
||||
return (true, val);
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,18 +213,18 @@ function length(${name} storage map) internal view returns (uint256) {
|
||||
*
|
||||
* - \`index\` must be strictly less than {length}.
|
||||
*/
|
||||
function at(${name} storage map, uint256 index) internal view returns (${keyType}, ${valueType}) {
|
||||
(bytes32 key, bytes32 value) = at(map._inner, index);
|
||||
return (${fromBytes32(keyType, 'key')}, ${fromBytes32(valueType, 'value')});
|
||||
function at(${name} storage map, uint256 index) internal view returns (${keyType} key, ${valueType} value) {
|
||||
(bytes32 atKey, bytes32 val) = at(map._inner, index);
|
||||
return (${fromBytes32(keyType, 'atKey')}, ${fromBytes32(valueType, 'val')});
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Tries to returns the value associated with \`key\`. O(1).
|
||||
* Does not revert if \`key\` is not in the map.
|
||||
*/
|
||||
function tryGet(${name} storage map, ${keyType} key) internal view returns (bool, ${valueType}) {
|
||||
(bool success, bytes32 value) = tryGet(map._inner, ${toBytes32(keyType, 'key')});
|
||||
return (success, ${fromBytes32(valueType, 'value')});
|
||||
function tryGet(${name} storage map, ${keyType} key) internal view returns (bool exists, ${valueType} value) {
|
||||
(bool success, bytes32 val) = tryGet(map._inner, ${toBytes32(keyType, 'key')});
|
||||
return (success, ${fromBytes32(valueType, 'val')});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user