Skip to content

Commit

Permalink
feat: small performance improvement constructing outgoing questions (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Dec 15, 2023
1 parent 6560fad commit 157185f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/zeroconf/_protocol/outgoing.pxd
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/zeroconf/_protocol/outgoing.py
Expand Up @@ -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)):
Expand Down

0 comments on commit 157185f

Please sign in to comment.