Skip to content
Open
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
11 changes: 6 additions & 5 deletions contracts/lib/AddressArrayUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ library AddressArrayUtils {
internal
{
(uint256 index, bool isIn) = indexOf(A, a);
if (!isIn) {
revert("Address not in array.");
} else {
uint256 lastIndex = A.length - 1; // If the array would be empty, the previous line would throw, so no underflow here
if (index != lastIndex) { A[index] = A[lastIndex]; }

if (isIn) { // address a is in array A, so array A is not emtpy, and A.length >= 1
uint256 lastIndex = A.length - 1;
A[index] = A[lastIndex]; // for save gas, we not check: index != lastIndex
A.pop();
} else {
revert("Address not in array.");
}
}

Expand Down
11 changes: 6 additions & 5 deletions contracts/lib/StringArrayUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ library StringArrayUtils {
internal
{
(uint256 index, bool isIn) = indexOf(A, a);
if (!isIn) {
revert("String not in array.");
} else {
uint256 lastIndex = A.length - 1; // If the array would be empty, the previous line would throw, so no underflow here
if (index != lastIndex) { A[index] = A[lastIndex]; }

if (isIn) { // string a is in the array A, so array A is not empty, and A.length >= 1
uint256 lastIndex = A.length - 1;
A[index] = A[lastIndex]; // to save gas, we not check: index != lastIndex
A.pop();
} else {
revert("String not in array.");
}
}
}