solmate icon indicating copy to clipboard operation
solmate copied to clipboard

Optimized Bytes32AddressLibs by using assembly and bit operations

Open malik672 opened this issue 1 year ago • 0 comments

Description

Optimized Bytes32AddressLibs by using assembly and bit operations

used assembly and bit operations to save 31+ in runtime gas Previously

library Bytes32AddressLib {
    function fillLast12Bytes(address addressValue) internal pure returns (bytes32) {
        return bytes32(bytes20(addressValue));
    }
}

Changes

    function fillLast12Byte(address addressValue)
        external
        pure
        returns (bytes32 _addr)
    {
        assembly{
            _addr := shl(96, addressValue)
        }
    }

malik672 avatar Oct 14 '23 20:10 malik672