Skip to content

Commit

Permalink
Remove duplicated SLOAD in Arrays.findUpperBound (#4442)
Browse files Browse the repository at this point in the history
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: Francisco Giordano <fg@frang.io>
  • Loading branch information
3 people authored Jul 12, 2023
1 parent 921ac49 commit 0abf18f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-countries-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`Arrays`: Optimize `findUpperBound` by removing redundant SLOAD.
8 changes: 4 additions & 4 deletions contracts/utils/Arrays.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ library Arrays {
* repeated elements.
*/
function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
if (array.length == 0) {
return 0;
}

uint256 low = 0;
uint256 high = array.length;

if (high == 0) {
return 0;
}

while (low < high) {
uint256 mid = Math.average(low, high);

Expand Down

0 comments on commit 0abf18f

Please sign in to comment.