Last active
November 23, 2022 16:08
-
-
Save Cr0wn-Gh0ul/421a20fc27d57fe0cb314dc4018b9333 to your computer and use it in GitHub Desktop.
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: Unlicense | |
pragma solidity ^0.8.13; | |
library CalldataUtils { | |
function concatMemCall(bytes memory a_, bytes calldata b_) | |
public | |
pure | |
returns (bytes memory ret) | |
{ | |
ret = new bytes(b_.length + a_.length); | |
assembly { | |
let al := mload(a_) | |
mstore(ret, add(al, b_.length)) | |
let c := add(ret, 0x20) | |
let e := add(c, al) | |
for { | |
let cc := add(a_, 0x20) | |
} lt(c, e) { | |
c := add(c, 0x20) | |
cc := add(cc, 0x20) | |
} { | |
mstore(c, mload(cc)) | |
} | |
calldatacopy(add(ret, add(0x20, al)), b_.offset, b_.length) | |
} | |
return ret; | |
} | |
function concatCalls(bytes calldata a_, bytes calldata b_) | |
public | |
pure | |
returns (bytes memory ret) | |
{ | |
ret = new bytes(b_.length + a_.length); | |
assembly { | |
mstore(ret, add(b_.length, a_.length)) | |
calldatacopy(add(ret, 0x20), a_.offset, a_.length) | |
calldatacopy(add(ret, add(0x20, a_.length)), b_.offset, b_.length) | |
} | |
return ret; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment