Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perf/heap ordering 1 #69

Closed
wants to merge 2 commits into from
Closed
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
22 changes: 13 additions & 9 deletions contracts/HeapOrdering.sol
Original file line number Diff line number Diff line change
Expand Up @@ -274,26 +274,28 @@ library HeapOrdering {
if (index >= _heap.accounts.length) return 0;
Account memory account = _heap.accounts[index];
if (account.id != _id) return 0;
else return account.value;
return account.value;
}

/// @notice Returns the address at the head of the `_heap`.
/// @param _heap The heap to get the head.
/// @return The address of the head.
function getHead(HeapArray storage _heap) internal view returns (address) {
if (_heap.accounts.length > 0) return _heap.accounts[ROOT].id;
else return address(0);
return address(0);
}

/// @notice Returns the address at the tail of unsorted portion of the `_heap`.
/// @param _heap The heap to get the tail.
/// @return The address of the tail.
function getTail(HeapArray storage _heap) internal view returns (address) {
uint256 accountsLength = _heap.accounts.length;
unchecked {
if (accountsLength > 0) return _heap.accounts[accountsLength - 1].id;
else return address(0);
if (accountsLength > 0) {
unchecked {
return _heap.accounts[accountsLength - 1].id;
}
}
return address(0);
}

/// @notice Returns the address coming before `_id` in accounts.
Expand All @@ -303,10 +305,12 @@ library HeapOrdering {
/// @return The address of the previous account.
function getPrev(HeapArray storage _heap, address _id) internal view returns (address) {
uint256 index = _heap.indexOf[_id];
unchecked {
if (index > ROOT) return _heap.accounts[index - 1].id;
else return address(0);
if (index > ROOT) {
unchecked {
return _heap.accounts[index - 1].id;
}
}
return address(0);
}

/// @notice Returns the address coming after `_id` in accounts.
Expand All @@ -319,7 +323,7 @@ library HeapOrdering {
unchecked {
if (index + 1 >= _heap.accounts.length || _heap.accounts[index].id != _id)
return address(0);
else return _heap.accounts[index + 1].id;
return _heap.accounts[index + 1].id;
}
}
}