answer - Nope

function loopCheck1(uint256[] memory arr) external returns (uint256[] memory) {
gas = gasleft(); // 29863 gas
uint length = arr.length;
for (uint i; i < length;) {
unchecked { ++i; }
}
return arr;
gas -= gasleft();
}

function loopCheck2(uint256[] memory arr) external returns (uint256[] memory) {
gas = gasleft();
uint i;
uint length = arr.length;
for (; i < length;) { // 29912 gas
unchecked { ++i; }
}
return arr;
gas -= gasleft();
}

Jul 16, 2022, 9:25 PM
that costs more doesn't make sense
ok nope maybe i fucked up lol
https://github.com/JoshuaTrujillo15/loopinator/blob/main/src/Loopinator.sol
looking to this thought was cheaper
Jul 16, 2022, 9:34 PM
uh that's cool, first time I see functions passed around as input in solidity, wasn't expecting that to be supported
Jul 16, 2022, 9:35 PM
not clear for me how this might work
Jul 16, 2022, 9:45 PM
My guess would be that when calling it you just have to pass the function selector of a function (no external calls)
Jul 16, 2022, 9:51 PM
Yeah, but i thought there needed to be function name
Jul 16, 2022, 9:53 PM
And when calling func(a) inside the code since the compiler knows what's the func's interface it would just do a call padding the selector with the abi encoded data
Oh just noticed there's an example of usage in the repository, very cool, looks exactly like with C/C++
Jul 16, 2022, 9:55 PM

© 2024 Draquery.com All rights reserved.