Skip to content

Commit

Permalink
Change && to nested ifs (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized authored May 5, 2022
1 parent df74e02 commit 17fb77f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions contracts/ERC721A.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ contract ERC721A is Context, ERC165, IERC721A {
uint256 curr = tokenId;

unchecked {
if (_startTokenId() <= curr && curr < _currentIndex) {
if (_startTokenId() <= curr) if (curr < _currentIndex) {
TokenOwnership memory ownership = _ownerships[curr];
if (!ownership.burned) {
if (ownership.addr != address(0)) {
Expand Down Expand Up @@ -210,7 +210,7 @@ contract ERC721A is Context, ERC165, IERC721A {
address owner = ERC721A.ownerOf(tokenId);
if (to == owner) revert ApprovalToCurrentOwner();

if (_msgSender() != owner && !isApprovedForAll(owner, _msgSender())) {
if (_msgSender() != owner) if(!isApprovedForAll(owner, _msgSender())) {
revert ApprovalCallerNotOwnerNorApproved();
}

Expand Down Expand Up @@ -275,7 +275,7 @@ contract ERC721A is Context, ERC165, IERC721A {
bytes memory _data
) public virtual override {
_transfer(from, to, tokenId);
if (to.isContract() && !_checkContractOnERC721Received(from, to, tokenId, _data)) {
if (to.isContract()) if(!_checkContractOnERC721Received(from, to, tokenId, _data)) {
revert TransferToNonERC721ReceiverImplementer();
}
}
Expand Down

2 comments on commit 17fb77f

@superpower007
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

solidity has short-circuit, so the change is not necessary

@Vectorized
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It saves gas. Try profiling && vs nested ifs.

Please sign in to comment.