Created
September 2, 2024 15:19
-
-
Save drgorillamd/48f9636a0de5e7b0dd6d917a480f958b to your computer and use it in GitHub Desktop.
calldata array length cached or nah?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity ^0.8.26; | |
import {Test, console} from "forge-std/Test.sol"; | |
// Ran 2 tests for test/Counter.t copy.sol:LenCalldata | |
// [PASS] test_test1() (gas: 15999) | |
// [PASS] test_test2() (gas: 15979) | |
contract LenCalldata is Test { | |
Test1 test1; | |
Test2 test2; | |
function setUp() public { | |
test1 = new Test1(); | |
test2 = new Test2(); | |
} | |
function test_test1() public { | |
uint256[] memory data = new uint256[](10); | |
test1.set(data); | |
} | |
function test_test2() public { | |
uint256[] memory data = new uint256[](10); | |
test2.set(data); | |
} | |
} | |
contract Test1 { | |
function set(uint256[] calldata data) external { | |
uint256 len = data.length; | |
for (uint256 i = 0; i < len; i++) { | |
console.log('meh'); | |
} | |
} | |
} | |
contract Test2 { | |
function set(uint256[] calldata data) public { | |
for (uint256 i = 0; i < data.length; i++) { | |
console.log('meh'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment