I have used in burn() function of NFT Contract.
function burn(address to, uint256 tokenId) external {
require(_exists(tokenId), "Contract: operator query for nonexistent token");
for (uint256 i = 0; i < _tokenIds.length; i ++) {
if (_tokenIds[i] == tokenId) {
_tokenIds[i] = _tokenIds[_tokenIds.length - 1];
_tokenIds.pop();
}
}
// Clear metadata (if any)
delete _Info[tokenId];
delete _tokenOwnersMap[tokenId];
delete _tokenApprovalsMap[tokenId];
emit Burn(to, tokenId);
}
According to some resources on internet, loops and use of delete cause more gas consumption, is that correct? Any other alternative for delete?