transmissions11 / solmate

Modern, opinionated, and gas optimized building blocks for smart contract development.
GNU Affero General Public License v3.0
3.87k stars 638 forks source link

Optimized Bytes32AddressLibs by using assembly and bit operations #394

Open malik672 opened 11 months ago

malik672 commented 11 months ago

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)
        }
    }