I have a mapping linking an email (bytes32) to an Id (uint256) named emailToId
:
mapping(bytes32 => uint256) public emailToId;
I also have functions in my smart contract that use this mapping, but I don't know what is better:
1 - use the mapping every time I need it
function changeUserNameAndEmail (
bytes32 email,
bytes32 newName,
bytes32 newEmail
) public {
users[emailToId[email]].name = newName;
emailToId[newEmail] = emailToId[email];
delete emailToId[email];
}
2 - store the mapping result in a variable userId
and re-use the variable every time I need it
function changeUserNameAndEmail (
bytes32 email,
bytes32 newName,
bytes32 newEmail
) public {
uint256 userId = emailToId[email];
users[userId].name = newName;
emailToId[newEmail] = userId;
delete emailToId[email];
}
PS: this is a simple example, but there are some functions that I need to use the emailToId[email] several times... should I use the mapping or store it in a variable in terms of gas cost and performance?