From dea21e34e503b9a443b40633209f06173acbc041 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 15 Dec 2023 08:22:05 -1000 Subject: [PATCH] feat: small performance improvement constructing outgoing questions --- src/zeroconf/_protocol/outgoing.pxd | 6 +++--- src/zeroconf/_protocol/outgoing.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/zeroconf/_protocol/outgoing.pxd b/src/zeroconf/_protocol/outgoing.pxd index 3460f0c74..4353757a0 100644 --- a/src/zeroconf/_protocol/outgoing.pxd +++ b/src/zeroconf/_protocol/outgoing.pxd @@ -127,16 +127,16 @@ cdef class DNSOutgoing: ) cpdef packets(self) - cpdef add_question_or_all_cache(self, DNSCache cache, object now, str name, object type_, object class_) + cpdef add_question_or_all_cache(self, DNSCache cache, double now, str name, object type_, object class_) - cpdef add_question_or_one_cache(self, DNSCache cache, object now, str name, object type_, object class_) + cpdef add_question_or_one_cache(self, DNSCache cache, double now, str name, object type_, object class_) cpdef add_question(self, DNSQuestion question) cpdef add_answer(self, DNSIncoming inp, DNSRecord record) @cython.locals(now_double=double) - cpdef add_answer_at_time(self, DNSRecord record, object now) + cpdef add_answer_at_time(self, DNSRecord record, double now) cpdef add_authorative_answer(self, DNSPointer record) diff --git a/src/zeroconf/_protocol/outgoing.py b/src/zeroconf/_protocol/outgoing.py index e94cd0d2d..57f981690 100644 --- a/src/zeroconf/_protocol/outgoing.py +++ b/src/zeroconf/_protocol/outgoing.py @@ -148,9 +148,9 @@ def add_question(self, record: DNSQuestion) -> None: def add_answer(self, inp: DNSIncoming, record: DNSRecord) -> None: """Adds an answer""" if not record.suppressed_by(inp): - self.add_answer_at_time(record, 0) + self.add_answer_at_time(record, 0.0) - def add_answer_at_time(self, record: Optional[DNSRecord], now: Union[float, int]) -> None: + def add_answer_at_time(self, record: Optional[DNSRecord], now: float_) -> None: """Adds an answer if it does not expire by a certain time""" now_double = now if record is not None and (now_double == 0 or not record.is_expired(now_double)):