1
1
// SPDX-License-Identifier: MIT
2
2
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Arrays.sol)
3
+ // This file was procedurally generated from scripts/generate/templates/Arrays.js.
3
4
4
5
pragma solidity ^ 0.8.20 ;
5
6
@@ -35,11 +36,20 @@ library Arrays {
35
36
* @dev Variant of {sort} that sorts an array of bytes32 in increasing order.
36
37
*/
37
38
function sort (bytes32 [] memory array ) internal pure returns (bytes32 [] memory ) {
38
- return sort (array, _defaultComp);
39
+ sort (array, _defaultComp);
40
+ return array;
39
41
}
40
42
41
43
/**
42
- * @dev Variant of {sort} that sorts an array of address following a provided comparator function.
44
+ * @dev Sort an array of address (in memory) following the provided comparator function.
45
+ *
46
+ * This function does the sorting "in place", meaning that it overrides the input. The object is returned for
47
+ * convenience, but that returned value can be discarded safely if the caller has a memory pointer to the array.
48
+ *
49
+ * NOTE: this function's cost is `O(n · log(n))` in average and `O(n²)` in the worst case, with n the length of the
50
+ * array. Using it in view functions that are executed through `eth_call` is safe, but one should be very careful
51
+ * when executing this as part of a transaction. If the array being sorted is too large, the sort operation may
52
+ * consume more gas than is available in a block, leading to potential DoS.
43
53
*/
44
54
function sort (
45
55
address [] memory array ,
@@ -58,7 +68,15 @@ library Arrays {
58
68
}
59
69
60
70
/**
61
- * @dev Variant of {sort} that sorts an array of uint256 following a provided comparator function.
71
+ * @dev Sort an array of uint256 (in memory) following the provided comparator function.
72
+ *
73
+ * This function does the sorting "in place", meaning that it overrides the input. The object is returned for
74
+ * convenience, but that returned value can be discarded safely if the caller has a memory pointer to the array.
75
+ *
76
+ * NOTE: this function's cost is `O(n · log(n))` in average and `O(n²)` in the worst case, with n the length of the
77
+ * array. Using it in view functions that are executed through `eth_call` is safe, but one should be very careful
78
+ * when executing this as part of a transaction. If the array being sorted is too large, the sort operation may
79
+ * consume more gas than is available in a block, leading to potential DoS.
62
80
*/
63
81
function sort (
64
82
uint256 [] memory array ,
0 commit comments