You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
although they are view functions, it's cheaper to simply return _ownerOf[id] & _balanceOf[owner]. Also, it's more developer-friendly or flexible I think.
Like in this test code:
/// address who owns the nft token id, can only burnfunction testBurnWorks() public {
vm.expectEmit(true, true, true, true);
emitBurned(ALICE, 1);
vm.prank(ALICE);
myNFT.burn(1);
// assertEq(myNFT.ownerOf(1), address(0));
}
I could call simply ownerOf function after burning NFT to verify. Otherwise, i have to use new_balance - old_balance.
Background
In this line:
solmate/src/tokens/ERC721.sol
Line 36 in c93f771
solmate/src/tokens/ERC721.sol
Line 40 in c93f771
although they are
view
functions, it's cheaper to simply return_ownerOf[id]
&_balanceOf[owner]
. Also, it's more developer-friendly or flexible I think.Like in this test code:
I could call simply
ownerOf
function after burning NFT to verify. Otherwise, i have to usenew_balance - old_balance
.Analysis
ownerOf
The current code costs
622
gas:Modifying the code with:
Function code (NEW):
The new code would cost
588
gas:balanceOf
Same reasoning in
balanceOf
function with new function code:Summary
ownerOf
function, we can save by52 gas
per call.balanceOf
function, we can save by34 gas
per call.The text was updated successfully, but these errors were encountered: