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

Slightly faster PortRef comparisons #228

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions hdl21/portref.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ class PortRef:
inst: _Instance
portname: str

__slots__ = (
"inst",
"portname",
"_connected_ports",
"resolved",
"_slices",
"_concats",
"_width",
)

def __post_init__(self):
# Inner management data
self._connected_ports: Set[PortRef] = set()
Expand All @@ -35,9 +45,10 @@ def __post_init__(self):
def __eq__(self, other) -> bool:
"""Port-reference equality requires *identity* between instances
(and of course equality of port-name)."""
if not isinstance(other, PortRef):
try:
return self.inst is other.inst and self.portname == other.portname
except AttributeError:
return False
return self.inst is other.inst and self.portname == other.portname

def __hash__(self):
"""Hash references as the tuple of their instance-address and name"""
Expand Down
Loading