I have two snippets -- one using memory, the other referencing storage:
function winnerName() public view
returns (string memory winnerName_)
{
string memory winnerName_ = proposals[0].name;
}
function winnerName() public view
returns (string memory winnerName_)
{
string storage winnerName_ = proposals[0].name;
}
The gas used for executing both snippets is the same (as per ganache). This seems surprising to me, given that memory
creates a copy and thus is more expensive.
Is this an optimization under the hood? I've used truffle compile
to compile the contract.