Skip to content

Commit

Permalink
Merge pull request wighawag#5 from Dobrokhvalov/uint256-array-in-immu…
Browse files Browse the repository at this point in the history
…table-args

Add function to read uint256[] array from immutable args
  • Loading branch information
wighawag authored Feb 2, 2022
2 parents 5950723 + cf0be92 commit c44a7f0
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Clone.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ contract Clone {
}
}

/// @notice Reads a uint256 array stored in the immutable args.
/// @param argOffset The offset of the arg in the packed data
/// @param arrLen Number of elements in the array
/// @return arr The array
function _getArgUint256Array(uint256 argOffset, uint64 arrLen)
internal
pure
returns (uint256[] memory arr)
{
uint256 offset = _getImmutableArgsOffset();
uint256 el;
arr = new uint256[](arrLen);
for (uint64 i = 0; i < arrLen; i++) {
assembly {
// solhint-disable-next-line no-inline-assembly
el := calldataload(add(add(offset, argOffset), mul(i, 32)))
}
arr[i] = el;
}
return arr;
}

/// @notice Reads an immutable arg with type uint64
/// @param argOffset The offset of the arg in the packed data
/// @return arg The arg value
Expand Down

0 comments on commit c44a7f0

Please sign in to comment.