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

Update AttestationRegistry.sol: Optimized 'For' loops #272

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
21 changes: 17 additions & 4 deletions contracts/src/AttestationRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,16 @@ contract AttestationRegistry is OwnableUpgradeable {
* @param attestationsPayloads the attestations payloads to create attestations and register them
*/
function bulkAttest(AttestationPayload[] calldata attestationsPayloads, address attester) public {
for (uint256 i = 0; i < attestationsPayloads.length; i++) {
for (uint256 i; i < attestationsPayloads.length;) {
attest(attestationsPayloads[i], attester);
unchecked {
++i;
}
}
}

function massImport(AttestationPayload[] calldata attestationsPayloads, address portal) public onlyOwner {
for (uint256 i = 0; i < attestationsPayloads.length; i++) {
for (uint256 i; i < attestationsPayloads.length;) {
// Auto increment attestation counter
attestationIdCounter++;
bytes32 id = bytes32(abi.encode(attestationIdCounter));
Expand All @@ -147,6 +150,10 @@ contract AttestationRegistry is OwnableUpgradeable {
attestationsPayloads[i].attestationData
);
emit AttestationRegistered(id);

unchecked {
++i;
}
}
}

Expand Down Expand Up @@ -203,8 +210,11 @@ contract AttestationRegistry is OwnableUpgradeable {
* @param attestationIds the IDs of the attestations to revoke
*/
function bulkRevoke(bytes32[] memory attestationIds) external {
for (uint256 i = 0; i < attestationIds.length; i++) {
for (uint256 i; i < attestationIds.length;) {
revoke(attestationIds[i]);
unchecked {
++i;
}
}
}

Expand Down Expand Up @@ -287,8 +297,11 @@ contract AttestationRegistry is OwnableUpgradeable {
function balanceOfBatch(address[] memory accounts, uint256[] memory ids) public view returns (uint256[] memory) {
if (accounts.length != ids.length) revert ArrayLengthMismatch();
uint256[] memory result = new uint256[](accounts.length);
for (uint256 i = 0; i < accounts.length; i++) {
for (uint256 i; i < accounts.length;) {
result[i] = balanceOf(accounts[i], ids[i]);
unchecked {
++i;
}
}
return result;
}
Expand Down
Loading