feat: speed up decoding dns questions when processing incoming data (… · python-zeroconf/python-zeroconf@f927190

2 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -38,6 +38,7 @@ from .._dns cimport (

3838

DNSHinfo,

3939

DNSNsec,

4040

DNSPointer,

41+

DNSQuestion,

4142

DNSRecord,

4243

DNSService,

4344

DNSText,

@@ -48,11 +49,11 @@ cdef class DNSIncoming:

4849
4950

cdef bint _did_read_others

5051

cdef public unsigned int flags

51-

cdef object offset

52+

cdef cython.uint offset

5253

cdef public bytes data

5354

cdef unsigned int _data_len

5455

cdef public cython.dict name_cache

55-

cdef public object questions

56+

cdef public cython.list questions

5657

cdef object _answers

5758

cdef public object id

5859

cdef public cython.uint num_questions

Original file line numberDiff line numberDiff line change

@@ -211,9 +211,12 @@ def _read_header(self) -> None:

211211
212212

def _read_questions(self) -> None:

213213

"""Reads questions section of packet"""

214-

self.questions = [

215-

DNSQuestion(self._read_name(), *self._unpack(UNPACK_HH, 4)) for _ in range(self.num_questions)

216-

]

214+

for _ in range(self.num_questions):

215+

name = self._read_name()

216+

type_, class_ = UNPACK_HH(self.data, self.offset)

217+

self.offset += 4

218+

question = DNSQuestion(name, type_, class_)

219+

self.questions.append(question)

217220
218221

def _read_character_string(self) -> bytes:

219222

"""Reads a character string from the packet"""