Uniswap / v2-periphery

🎚 Peripheral smart contracts for interacting with Uniswap V2
https://uniswap.org/docs
GNU General Public License v3.0
1.14k stars 1.69k forks source link

change memory to calldata #152

Closed molly-ting closed 1 year ago

molly-ting commented 1 year ago

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];
    }
molly-ting commented 1 year ago

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.