Skip to content

Commit

Permalink
feat: recycle Signatures for faster Call init (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Sep 27, 2023
1 parent 9b90115 commit 426bd7e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions multicall/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from eth_utils import to_checksum_address
from web3 import Web3

from multicall import Signature
from multicall import Signature, _get_signature
from multicall.constants import Network, w3
from multicall.exceptions import StateOverrideNotSupported
from multicall.loggers import setup_logger
Expand Down Expand Up @@ -44,7 +44,7 @@ def __init__(
self.function = function
self.args = None

self.signature = Signature(self.function)
self.signature = _get_signature(self.function)

def __repr__(self) -> str:
return f'<Call {self.function} on {self.target[:8]}>'
Expand Down
3 changes: 3 additions & 0 deletions multicall/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def parse_typestring(typestring: str) -> Optional[List[TypeStr]]:
parts.append(part)
return parts

@lru_cache(maxsize=None)
def _get_signature(signature: str) -> "Signature":
return Signature(signature)

class Signature:
__slots__ = "signature", "function", "input_types", "output_types"
Expand Down

0 comments on commit 426bd7e

Please sign in to comment.