Skip to content

Commit 0abf18f

Browse files
molly-tingAmxxfrangio
authored
Remove duplicated SLOAD in Arrays.findUpperBound (#4442)
Co-authored-by: Hadrien Croubois <[email protected]> Co-authored-by: Francisco Giordano <[email protected]>
1 parent 921ac49 commit 0abf18f

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

.changeset/fluffy-countries-buy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openzeppelin-solidity': minor
3+
---
4+
5+
`Arrays`: Optimize `findUpperBound` by removing redundant SLOAD.

contracts/utils/Arrays.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ library Arrays {
2222
* repeated elements.
2323
*/
2424
function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
25-
if (array.length == 0) {
26-
return 0;
27-
}
28-
2925
uint256 low = 0;
3026
uint256 high = array.length;
3127

28+
if (high == 0) {
29+
return 0;
30+
}
31+
3232
while (low < high) {
3333
uint256 mid = Math.average(low, high);
3434

0 commit comments

Comments
 (0)