In the examples I updated, the argument has the storage location memory.
When the functions get called externally, the arguments are kept in calldata
and copied to memory during ABI decoding (using the opcode calldataload and mstore).
When the argument is read in the function, the value is accesses in memory
using a mload. We can avoid all this logic by simply using calldata for
read-only arguments. In my proposal, instead of going via memory,
the value is directly read from calldata using calldataload.
I think this is important to expose good practices like this one to the user.
What do you think about this @t4sk? I'm ready to open a PR that changes memory argument to calldata argument when needed.
In the examples I updated, the argument has the storage location memory. When the functions get called externally, the arguments are kept in calldata and copied to memory during ABI decoding (using the opcode calldataload and mstore). When the argument is read in the function, the value is accesses in memory using a mload. We can avoid all this logic by simply using calldata for read-only arguments. In my proposal, instead of going via memory, the value is directly read from calldata using calldataload. I think this is important to expose good practices like this one to the user.
What do you think about this @t4sk? I'm ready to open a PR that changes memory argument to calldata argument when needed.