Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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