Skip to content

Commit 22e4a29

Browse files
authored
feat: speed up adding and removing RecordUpdateListeners (#1253)
1 parent 72d6886 commit 22e4a29

4 files changed

Lines changed: 9 additions & 8 deletions

File tree

src/zeroconf/_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ async def async_wait_for_start(self) -> None:
240240
raise NotRunningException
241241

242242
@property
243-
def listeners(self) -> List[RecordUpdateListener]:
243+
def listeners(self) -> Set[RecordUpdateListener]:
244244
return self.record_manager.listeners
245245

246246
async def async_wait(self, timeout: float) -> None:

src/zeroconf/_handlers/record_manager.pxd

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ cdef object RecordUpdate
1212
cdef object TYPE_CHECKING
1313
cdef object _TYPE_PTR
1414

15+
1516
cdef class RecordManager:
1617

1718
cdef public object zc
1819
cdef public DNSCache cache
19-
cdef public cython.list listeners
20+
cdef public cython.set listeners
2021

2122
cpdef async_updates(self, object now, object records)
2223

@@ -29,3 +30,7 @@ cdef class RecordManager:
2930
now_float=cython.float
3031
)
3132
cpdef async_updates_from_response(self, DNSIncoming msg)
33+
34+
cpdef async_add_listener(self, object listener, object question)
35+
36+
cpdef async_remove_listener(self, object listener)

src/zeroconf/_handlers/record_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(self, zeroconf: 'Zeroconf') -> None:
4545
"""Init the record manager."""
4646
self.zc = zeroconf
4747
self.cache = zeroconf.cache
48-
self.listeners: List[RecordUpdateListener] = []
48+
self.listeners: Set[RecordUpdateListener] = set()
4949

5050
def async_updates(self, now: _float, records: List[RecordUpdate]) -> None:
5151
"""Used to notify listeners of new information that has updated
@@ -175,7 +175,7 @@ def async_add_listener(
175175
" In the future this will fail"
176176
)
177177

178-
self.listeners.append(listener)
178+
self.listeners.add(listener)
179179

180180
if question is None:
181181
return

src/zeroconf/_services/info.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -758,10 +758,6 @@ def generate_request_query(
758758
question.unicast = True
759759
return out
760760

761-
def __eq__(self, other: object) -> bool:
762-
"""Tests equality of service name"""
763-
return isinstance(other, ServiceInfo) and other._name == self._name
764-
765761
def __repr__(self) -> str:
766762
"""String representation"""
767763
return '{}({})'.format(

0 commit comments

Comments
 (0)