Skip to content

Commit

Permalink
Tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized committed Aug 21, 2024
1 parent d1e624c commit 1f4ff52
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions contracts/ERC721A.sol
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,8 @@ contract ERC721A is IERC721A {
// Disallow transfer to zero address.
if (toMasked == uint256(0)) _revert(TransferToZeroAddress.selector);
// Whether we need to check the individual token approvals.
bool approvalCheck = byMasked != uint256(0) && byMasked != fromMasked && !isApprovedForAll(from, by);
bool approvalCheck;
if (!_orERC721A(byMasked == uint256(0), byMasked == fromMasked)) approvalCheck = !isApprovedForAll(from, by);
uint256 n = tokenIds.length;
// Early return if `tokenIds` is empty.
if (n == uint256(0)) return;
Expand All @@ -755,10 +756,8 @@ contract ERC721A is IERC721A {
unchecked {
uint256 tokenId = _mloadERC721A(i); // For checking if the `tokenIds` are strictly ascending.
// Revert if the minimum of the `tokenIds` is out of bounds.
// This is equivalent to `tokenId < _startTokenId() || end <= tokenId`.
if (end - _startTokenId() <= tokenId - _startTokenId()) _revert(OwnerQueryForNonexistentToken.selector);
if (_orERC721A(tokenId < _startTokenId(), end <= tokenId)) _revert(OwnerQueryForNonexistentToken.selector);
_beforeTokenTransfers(from, to, tokenId, 1); // Perform the before hook.

if (n >= 2) {
uint256 j = i + 0x20;
do {
Expand Down Expand Up @@ -789,7 +788,7 @@ contract ERC721A is IERC721A {
// - `address` to the next owner.
// - `startTimestamp` to the timestamp of transferring.
// - `burned` to `false`.
// - `nextInitialized` to `false`.
// - `nextInitialized` to `false`, as it is optional.
_packedOwnerships[tokenId] = _packOwnershipData(to, _nextExtraData(from, to, prevOwnershipPacked));
do {
(uint256 approvedAddressSlot, uint256 approvedAddressValue) = _getApprovedSlotAndValue(tokenId);
Expand Down Expand Up @@ -1445,6 +1444,15 @@ contract ERC721A is IERC721A {
}
}

/**
* @dev Branchless boolean or.
*/
function _orERC721A(bool a, bool b) private pure returns (bool result) {
assembly {
result := or(iszero(iszero(a)), iszero(iszero(b)))
}
}

// =============================================================
// OTHER OPERATIONS
// =============================================================
Expand Down

0 comments on commit 1f4ff52

Please sign in to comment.