Skip to content

Commit

Permalink
Reduce overhead to compare dns records (#997)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Sep 23, 2021
1 parent 7622365 commit 7fa51de
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions zeroconf/_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def __hash__(self) -> int:

def __eq__(self, other: Any) -> bool:
"""Tests equality on dns question."""
return isinstance(other, DNSQuestion) and DNSEntry.__eq__(self, other)
return isinstance(other, DNSQuestion) and dns_entry_matches(other, self.key, self.type, self.class_)

@property
def max_size(self) -> int:
Expand Down Expand Up @@ -260,7 +260,7 @@ def __eq__(self, other: Any) -> bool:
isinstance(other, DNSAddress)
and self.address == other.address
and self.scope_id == other.scope_id
and DNSEntry.__eq__(self, other)
and dns_entry_matches(other, self.key, self.type, self.class_)
)

def __hash__(self) -> int:
Expand Down Expand Up @@ -304,7 +304,7 @@ def __eq__(self, other: Any) -> bool:
isinstance(other, DNSHinfo)
and self.cpu == other.cpu
and self.os == other.os
and DNSEntry.__eq__(self, other)
and dns_entry_matches(other, self.key, self.type, self.class_)
)

def __hash__(self) -> int:
Expand Down Expand Up @@ -345,7 +345,11 @@ def write(self, out: 'DNSOutgoing') -> None:

def __eq__(self, other: Any) -> bool:
"""Tests equality on alias"""
return isinstance(other, DNSPointer) and self.alias == other.alias and DNSEntry.__eq__(self, other)
return (
isinstance(other, DNSPointer)
and self.alias == other.alias
and dns_entry_matches(other, self.key, self.type, self.class_)
)

def __hash__(self) -> int:
"""Hash to compare like DNSPointer."""
Expand Down Expand Up @@ -380,7 +384,11 @@ def __hash__(self) -> int:

def __eq__(self, other: Any) -> bool:
"""Tests equality on text"""
return isinstance(other, DNSText) and self.text == other.text and DNSEntry.__eq__(self, other)
return (
isinstance(other, DNSText)
and self.text == other.text
and dns_entry_matches(other, self.key, self.type, self.class_)
)

def __repr__(self) -> str:
"""String representation"""
Expand Down Expand Up @@ -429,7 +437,7 @@ def __eq__(self, other: Any) -> bool:
and self.weight == other.weight
and self.port == other.port
and self.server == other.server
and DNSEntry.__eq__(self, other)
and dns_entry_matches(other, self.key, self.type, self.class_)
)

def __hash__(self) -> int:
Expand Down Expand Up @@ -484,7 +492,7 @@ def __eq__(self, other: Any) -> bool:
isinstance(other, DNSNsec)
and self.next_name == other.next_name
and self.rdtypes == other.rdtypes
and DNSEntry.__eq__(self, other)
and dns_entry_matches(other, self.key, self.type, self.class_)
)

def __hash__(self) -> int:
Expand Down

0 comments on commit 7fa51de

Please sign in to comment.