Changing the data location of function parameters from memory to calldata can save much gas.
In the following example, test4 saves about 955 units of gas.
function test3(uint256[] memory amounts) public {
uint256 amount = amounts[0];
}
function test4(uint256[] calldata amounts) public {
uint256 amount = amounts[0];
}
Sorry, I just found that calldata is typically used in external function and the functions I changed are private or internal. I'll close this pull request.
Changing the data location of function parameters from memory to calldata can save much gas. In the following example, test4 saves about 955 units of gas.