Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized Bytes32AddressLibs by using assembly and bit operations #394

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

malik672
Copy link

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 and others added 3 commits October 14, 2023 21:02
optimize fromLast20Bytes
optimized fillLast12Bytes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant