mirror of
https://github.com/lens-protocol/core.git
synced 2026-04-22 03:02:03 -04:00
refactor: Wrapped for loop iterators in unchecked blocks, also formatted with prettier.
This commit is contained in:
@@ -529,8 +529,11 @@ contract LensHub is ILensHub, LensNFTBase, VersionedInitializable, LensMultiStat
|
||||
whenNotPaused
|
||||
{
|
||||
bytes32[] memory dataHashes = new bytes32[](vars.datas.length);
|
||||
for (uint256 i = 0; i < vars.datas.length; ++i) {
|
||||
for (uint256 i = 0; i < vars.datas.length; ) {
|
||||
dataHashes[i] = keccak256(vars.datas[i]);
|
||||
unchecked {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
_validateRecoveredAddress(
|
||||
_calculateDigest(
|
||||
|
||||
@@ -38,8 +38,11 @@ contract ApprovalFollowModule is IFollowModule, FollowValidatorFollowModuleBase
|
||||
address owner = IERC721(HUB).ownerOf(profileId);
|
||||
if (msg.sender != owner) revert Errors.NotProfileOwner();
|
||||
|
||||
for (uint256 i = 0; i < addresses.length; ++i) {
|
||||
for (uint256 i = 0; i < addresses.length; ) {
|
||||
_approvedByProfileByOwner[owner][profileId][addresses[i]] = toApprove[i];
|
||||
unchecked {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
emit Events.FollowsApproved(owner, profileId, addresses, toApprove, block.timestamp);
|
||||
@@ -63,8 +66,11 @@ contract ApprovalFollowModule is IFollowModule, FollowValidatorFollowModuleBase
|
||||
|
||||
if (data.length > 0) {
|
||||
address[] memory addresses = abi.decode(data, (address[]));
|
||||
for (uint256 i = 0; i < addresses.length; ++i) {
|
||||
for (uint256 i = 0; i < addresses.length; ) {
|
||||
_approvedByProfileByOwner[owner][profileId][addresses[i]] = true;
|
||||
unchecked {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
@@ -125,8 +131,11 @@ contract ApprovalFollowModule is IFollowModule, FollowValidatorFollowModuleBase
|
||||
address[] calldata toCheck
|
||||
) external view returns (bool[] memory) {
|
||||
bool[] memory approved = new bool[](toCheck.length);
|
||||
for (uint256 i = 0; i < toCheck.length; ++i) {
|
||||
for (uint256 i = 0; i < toCheck.length; ) {
|
||||
approved[i] = _approvedByProfileByOwner[profileOwner][profileId][toCheck[i]];
|
||||
unchecked {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
return approved;
|
||||
}
|
||||
|
||||
@@ -68,5 +68,4 @@ interface IFollowNFT {
|
||||
* @param blockNumber The block number to query the delegated supply at.
|
||||
*/
|
||||
function getDelegatedSupplyByBlockNumber(uint256 blockNumber) external returns (uint256);
|
||||
|
||||
}
|
||||
|
||||
@@ -489,5 +489,4 @@ library Events {
|
||||
bool[] enabled,
|
||||
uint256 timestamp
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ library InteractionLogic {
|
||||
mapping(bytes32 => uint256) storage _profileIdByHandleHash
|
||||
) external {
|
||||
if (profileIds.length != followModuleDatas.length) revert Errors.ArrayMismatch();
|
||||
for (uint256 i = 0; i < profileIds.length; ++i) {
|
||||
for (uint256 i = 0; i < profileIds.length; ) {
|
||||
string memory handle = _profileById[profileIds[i]].handle;
|
||||
if (_profileIdByHandleHash[keccak256(bytes(handle))] != profileIds[i])
|
||||
revert Errors.TokenDoesNotExist();
|
||||
@@ -80,6 +80,9 @@ library InteractionLogic {
|
||||
followModuleDatas[i]
|
||||
);
|
||||
}
|
||||
unchecked {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -147,11 +147,14 @@ library ProfileTokenURILogic {
|
||||
if (imageURIBytes.length == 0) {
|
||||
return false;
|
||||
}
|
||||
for (uint256 i = 0; i < imageURIBytes.length; i++) {
|
||||
for (uint256 i = 0; i < imageURIBytes.length; ) {
|
||||
if (imageURIBytes[i] == '"') {
|
||||
// Avoids embedding a user provided imageURI containing double-quotes to prevent injection attacks
|
||||
return false;
|
||||
}
|
||||
unchecked {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -400,12 +400,15 @@ library PublishingLogic {
|
||||
if (byteHandle.length == 0 || byteHandle.length > Constants.MAX_HANDLE_LENGTH)
|
||||
revert Errors.HandleLengthInvalid();
|
||||
|
||||
for (uint256 i = 0; i < byteHandle.length; ++i) {
|
||||
for (uint256 i = 0; i < byteHandle.length; ) {
|
||||
if (
|
||||
(byteHandle[i] < '0' ||
|
||||
byteHandle[i] > 'z' ||
|
||||
(byteHandle[i] > '9' && byteHandle[i] < 'a')) && byteHandle[i] != '.'
|
||||
) revert Errors.HandleContainsInvalidCharacters();
|
||||
unchecked {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import {Errors} from '../libraries/Errors.sol';
|
||||
*
|
||||
* @dev This is useful because it allows clients to filter out follow NFTs that were transferred to
|
||||
* a recipient by another user (i.e. Not a mint) and not register them as "following" unless
|
||||
* the recipient explicitly toggles the follow here.
|
||||
* the recipient explicitly toggles the follow here.
|
||||
*/
|
||||
contract LensPeripheryDataProvider {
|
||||
string public constant NAME = 'LensPeripheryDataProvider';
|
||||
@@ -79,11 +79,14 @@ contract LensPeripheryDataProvider {
|
||||
bool[] calldata enables
|
||||
) internal {
|
||||
if (profileIds.length != enables.length) revert Errors.ArrayMismatch();
|
||||
for (uint256 i = 0; i < profileIds.length; ++i) {
|
||||
for (uint256 i = 0; i < profileIds.length; ) {
|
||||
address followNFT = HUB.getFollowNFT(profileIds[i]);
|
||||
if (followNFT == address(0)) revert Errors.FollowInvalid();
|
||||
if (!IERC721Time(address(HUB)).exists(profileIds[i])) revert Errors.TokenDoesNotExist();
|
||||
if (IERC721Time(followNFT).balanceOf(follower) == 0) revert Errors.FollowInvalid();
|
||||
unchecked {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
emit Events.FollowsToggled(follower, profileIds, enables, block.timestamp);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user