Merge branch 'solc-0.7' into solc-0.8
This commit is contained in:
@ -143,6 +143,16 @@ library EnumerableMap {
|
||||
return (entry._key, entry._value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Tries to returns the value associated with `key`. O(1).
|
||||
* Does not revert if `key` is not in the map.
|
||||
*/
|
||||
function _tryGet(Map storage map, bytes32 key) private view returns (bool, bytes32) {
|
||||
uint256 keyIndex = map._indexes[key];
|
||||
if (keyIndex == 0) return (false, 0); // Equivalent to contains(map, key)
|
||||
return (true, map._entries[keyIndex - 1]._value); // All indexes are 1-based
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the value associated with `key`. O(1).
|
||||
*
|
||||
@ -151,11 +161,16 @@ library EnumerableMap {
|
||||
* - `key` must be in the map.
|
||||
*/
|
||||
function _get(Map storage map, bytes32 key) private view returns (bytes32) {
|
||||
return _get(map, key, "EnumerableMap: nonexistent key");
|
||||
uint256 keyIndex = map._indexes[key];
|
||||
require(keyIndex != 0, "EnumerableMap: nonexistent key"); // Equivalent to contains(map, key)
|
||||
return map._entries[keyIndex - 1]._value; // All indexes are 1-based
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Same as {_get}, with a custom error message when `key` is not in the map.
|
||||
*
|
||||
* CAUTION: This function is deprecated because it requires allocating memory for the error
|
||||
* message unnecessarily. For custom revert reasons use {_tryGet}.
|
||||
*/
|
||||
function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) {
|
||||
uint256 keyIndex = map._indexes[key];
|
||||
@ -217,6 +232,15 @@ library EnumerableMap {
|
||||
return (uint256(key), address(uint160(uint256(value))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Tries to returns the value associated with `key`. O(1).
|
||||
* Does not revert if `key` is not in the map.
|
||||
*/
|
||||
function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) {
|
||||
(bool success, bytes32 value) = _tryGet(map._inner, bytes32(key));
|
||||
return (success, address(uint160(uint256(value))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the value associated with `key`. O(1).
|
||||
*
|
||||
@ -230,6 +254,9 @@ library EnumerableMap {
|
||||
|
||||
/**
|
||||
* @dev Same as {get}, with a custom error message when `key` is not in the map.
|
||||
*
|
||||
* CAUTION: This function is deprecated because it requires allocating memory for the error
|
||||
* message unnecessarily. For custom revert reasons use {tryGet}.
|
||||
*/
|
||||
function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) {
|
||||
return address(uint160(uint256(_get(map._inner, bytes32(key), errorMessage))));
|
||||
|
||||
Reference in New Issue
Block a user