feat: speed up ServiceBrowsers with a pxd for the signal interface (#… · python-zeroconf/python-zeroconf@8a17f20

4 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -33,6 +33,7 @@ def build(setup_kwargs: Any) -> None:

3333

"src/zeroconf/_handlers/record_manager.py",

3434

"src/zeroconf/_handlers/multicast_outgoing_queue.py",

3535

"src/zeroconf/_handlers/query_handler.py",

36+

"src/zeroconf/_services/__init__.py",

3637

"src/zeroconf/_services/browser.py",

3738

"src/zeroconf/_services/info.py",

3839

"src/zeroconf/_services/registry.py",

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,11 @@

1+
2+

import cython

3+
4+
5+

cdef class Signal:

6+
7+

cdef list _handlers

8+
9+

cdef class SignalRegistrationInterface:

10+
11+

cdef list _handlers

Original file line numberDiff line numberDiff line change

@@ -5,6 +5,7 @@ from .._cache cimport DNSCache

55

from .._protocol.outgoing cimport DNSOutgoing, DNSPointer, DNSQuestion, DNSRecord

66

from .._updates cimport RecordUpdateListener

77

from .._utils.time cimport current_time_millis, millis_to_seconds

8+

from . cimport Signal, SignalRegistrationInterface

89
910
1011

cdef bint TYPE_CHECKING

Original file line numberDiff line numberDiff line change

@@ -405,7 +405,7 @@ def _enqueue_callback(

405405

state_change is SERVICE_STATE_CHANGE_ADDED

406406

or (

407407

state_change is SERVICE_STATE_CHANGE_REMOVED

408-

and self._pending_handlers.get(key) != SERVICE_STATE_CHANGE_ADDED

408+

and self._pending_handlers.get(key) is not SERVICE_STATE_CHANGE_ADDED

409409

)

410410

or (state_change is SERVICE_STATE_CHANGE_UPDATED and key not in self._pending_handlers)

411411

):