feat: small speed up to processing incoming dns records (#1315) · python-zeroconf/python-zeroconf@bfe4c24
@@ -4,19 +4,21 @@ import cython
44from ._protocol.outgoing cimport DNSOutgoing
55667-cdef object _LEN_BYTE
8-cdef object _LEN_SHORT
9-cdef object _LEN_INT
7+cdef cython.uint _LEN_BYTE
8+cdef cython.uint _LEN_SHORT
9+cdef cython.uint _LEN_INT
101011-cdef object _NAME_COMPRESSION_MIN_SIZE
12-cdef object _BASE_MAX_SIZE
11+cdef cython.uint _NAME_COMPRESSION_MIN_SIZE
12+cdef cython.uint _BASE_MAX_SIZE
13131414cdef cython.uint _EXPIRE_FULL_TIME_MS
1515cdef cython.uint _EXPIRE_STALE_TIME_MS
1616cdef cython.uint _RECENT_TIME_MS
171718-cdef object _CLASS_UNIQUE
19-cdef object _CLASS_MASK
18+cdef cython.uint _TYPE_ANY
19+20+cdef cython.uint _CLASS_UNIQUE
21+cdef cython.uint _CLASS_MASK
20222123cdef object current_time_millis
2224@@ -25,36 +27,40 @@ cdef class DNSEntry:
2527 cdef public str key
2628 cdef public str name
2729 cdef public cython.uint type
28- cdef public object class_
29- cdef public object unique
30+ cdef public cython.uint class_
31+ cdef public bint unique
32+33+ cdef _set_class(self, cython.uint class_)
303431- cdef _dns_entry_matches(self, DNSEntry other)
35+ cdef bint _dns_entry_matches(self, DNSEntry other)
32363337cdef class DNSQuestion(DNSEntry):
34383539 cdef public cython.int _hash
364041+ cpdef bint answered_by(self, DNSRecord rec)
42+3743cdef class DNSRecord(DNSEntry):
38443945 cdef public cython.float ttl
4046 cdef public cython.float created
414742- cdef _suppressed_by_answer(self, DNSRecord answer)
48+ cdef bint _suppressed_by_answer(self, DNSRecord answer)
43494450@cython.locals(
4551answers=cython.list,
4652 )
47- cpdef suppressed_by(self, object msg)
53+ cpdef bint suppressed_by(self, object msg)
48544955 cpdef get_remaining_ttl(self, cython.float now)
50565157 cpdef get_expiration_time(self, cython.uint percent)
525853- cpdef is_expired(self, cython.float now)
59+ cpdef bint is_expired(self, cython.float now)
546055- cpdef is_stale(self, cython.float now)
61+ cpdef bint is_stale(self, cython.float now)
566257- cpdef is_recent(self, cython.float now)
63+ cpdef bint is_recent(self, cython.float now)
58645965 cpdef reset_ttl(self, DNSRecord other)
6066@@ -66,18 +72,18 @@ cdef class DNSAddress(DNSRecord):
6672 cdef public object address
6773 cdef public object scope_id
687469- cdef _eq(self, DNSAddress other)
75+ cdef bint _eq(self, DNSAddress other)
70767177 cpdef write(self, DNSOutgoing out)
727873797480cdef class DNSHinfo(DNSRecord):
75817682 cdef public cython.int _hash
77- cdef public object cpu
78- cdef public object os
83+ cdef public str cpu
84+ cdef public str os
798580- cdef _eq(self, DNSHinfo other)
86+ cdef bint _eq(self, DNSHinfo other)
81878288 cpdef write(self, DNSOutgoing out)
8389@@ -87,29 +93,29 @@ cdef class DNSPointer(DNSRecord):
8793 cdef public str alias
8894 cdef public str alias_key
899590- cdef _eq(self, DNSPointer other)
96+ cdef bint _eq(self, DNSPointer other)
91979298 cpdef write(self, DNSOutgoing out)
939994100cdef class DNSText(DNSRecord):
9510196102 cdef public cython.int _hash
97- cdef public object text
103+ cdef public bytes text
9810499- cdef _eq(self, DNSText other)
105+ cdef bint _eq(self, DNSText other)
100106101107 cpdef write(self, DNSOutgoing out)
102108103109cdef class DNSService(DNSRecord):
104110105111 cdef public cython.int _hash
106- cdef public object priority
107- cdef public object weight
108- cdef public object port
112+ cdef public cython.uint priority
113+ cdef public cython.uint weight
114+ cdef public cython.uint port
109115 cdef public str server
110116 cdef public str server_key
111117112- cdef _eq(self, DNSService other)
118+ cdef bint _eq(self, DNSService other)
113119114120 cpdef write(self, DNSOutgoing out)
115121@@ -119,7 +125,7 @@ cdef class DNSNsec(DNSRecord):
119125 cdef public object next_name
120126 cdef public cython.list rdtypes
121127122- cdef _eq(self, DNSNsec other)
128+ cdef bint _eq(self, DNSNsec other)
123129124130 cpdef write(self, DNSOutgoing out)
125131@@ -129,7 +135,7 @@ cdef class DNSRRSet:
129135 cdef cython.dict _lookup
130136131137@cython.locals(other=DNSRecord)
132- cpdef suppresses(self, DNSRecord record)
138+ cpdef bint suppresses(self, DNSRecord record)
133139134140@cython.locals(
135141record=DNSRecord,