@@ -67,12 +67,13 @@ class DNSEntry:
6767 __slots__ = ("class_" , "key" , "name" , "type" , "unique" )
6868
6969 def __init__ (self , name : str , type_ : int , class_ : int ) -> None :
70+ self ._fast_init_entry (name , type_ , class_ )
71+
72+ def _fast_init_entry (self , name : str , type_ : _int , class_ : _int ) -> None :
73+ """Fast init for reuse."""
7074 self .name = name
7175 self .key = name .lower ()
7276 self .type = type_
73- self ._set_class (class_ )
74-
75- def _set_class (self , class_ : _int ) -> None :
7677 self .class_ = class_ & _CLASS_MASK
7778 self .unique = (class_ & _CLASS_UNIQUE ) != 0
7879
@@ -111,7 +112,11 @@ class DNSQuestion(DNSEntry):
111112 __slots__ = ("_hash" ,)
112113
113114 def __init__ (self , name : str , type_ : int , class_ : int ) -> None :
114- super ().__init__ (name , type_ , class_ )
115+ self ._fast_init (name , type_ , class_ )
116+
117+ def _fast_init (self , name : str , type_ : _int , class_ : _int ) -> None :
118+ """Fast init for reuse."""
119+ self ._fast_init_entry (name , type_ , class_ )
115120 self ._hash = hash ((self .key , type_ , self .class_ ))
116121
117122 def answered_by (self , rec : "DNSRecord" ) -> bool :
@@ -168,9 +173,13 @@ def __init__(
168173 ttl : Union [float , int ],
169174 created : Optional [float ] = None ,
170175 ) -> None :
171- super ().__init__ (name , type_ , class_ )
176+ self ._fast_init_record (name , type_ , class_ , ttl , created or current_time_millis ())
177+
178+ def _fast_init_record (self , name : str , type_ : _int , class_ : _int , ttl : _float , created : _float ) -> None :
179+ """Fast init for reuse."""
180+ self ._fast_init_entry (name , type_ , class_ )
172181 self .ttl = ttl
173- self .created = created or current_time_millis ()
182+ self .created = created
174183
175184 def __eq__ (self , other : Any ) -> bool : # pylint: disable=no-self-use
176185 """Abstract method"""
@@ -248,7 +257,20 @@ def __init__(
248257 scope_id : Optional [int ] = None ,
249258 created : Optional [float ] = None ,
250259 ) -> None :
251- super ().__init__ (name , type_ , class_ , ttl , created )
260+ self ._fast_init (name , type_ , class_ , ttl , address , scope_id , created or current_time_millis ())
261+
262+ def _fast_init (
263+ self ,
264+ name : str ,
265+ type_ : _int ,
266+ class_ : _int ,
267+ ttl : _float ,
268+ address : bytes ,
269+ scope_id : Optional [_int ],
270+ created : _float ,
271+ ) -> None :
272+ """Fast init for reuse."""
273+ self ._fast_init_record (name , type_ , class_ , ttl , created )
252274 self .address = address
253275 self .scope_id = scope_id
254276 self ._hash = hash ((self .key , type_ , self .class_ , address , scope_id ))
@@ -300,7 +322,13 @@ def __init__(
300322 os : str ,
301323 created : Optional [float ] = None ,
302324 ) -> None :
303- super ().__init__ (name , type_ , class_ , ttl , created )
325+ self ._fast_init (name , type_ , class_ , ttl , cpu , os , created or current_time_millis ())
326+
327+ def _fast_init (
328+ self , name : str , type_ : _int , class_ : _int , ttl : _float , cpu : str , os : str , created : _float
329+ ) -> None :
330+ """Fast init for reuse."""
331+ self ._fast_init_record (name , type_ , class_ , ttl , created )
304332 self .cpu = cpu
305333 self .os = os
306334 self ._hash = hash ((self .key , type_ , self .class_ , cpu , os ))
@@ -341,7 +369,12 @@ def __init__(
341369 alias : str ,
342370 created : Optional [float ] = None ,
343371 ) -> None :
344- super ().__init__ (name , type_ , class_ , ttl , created )
372+ self ._fast_init (name , type_ , class_ , ttl , alias , created or current_time_millis ())
373+
374+ def _fast_init (
375+ self , name : str , type_ : _int , class_ : _int , ttl : _float , alias : str , created : _float
376+ ) -> None :
377+ self ._fast_init_record (name , type_ , class_ , ttl , created )
345378 self .alias = alias
346379 self .alias_key = alias .lower ()
347380 self ._hash = hash ((self .key , type_ , self .class_ , self .alias_key ))
@@ -391,7 +424,12 @@ def __init__(
391424 text : bytes ,
392425 created : Optional [float ] = None ,
393426 ) -> None :
394- super ().__init__ (name , type_ , class_ , ttl , created )
427+ self ._fast_init (name , type_ , class_ , ttl , text , created or current_time_millis ())
428+
429+ def _fast_init (
430+ self , name : str , type_ : _int , class_ : _int , ttl : _float , text : bytes , created : _float
431+ ) -> None :
432+ self ._fast_init_record (name , type_ , class_ , ttl , created )
395433 self .text = text
396434 self ._hash = hash ((self .key , type_ , self .class_ , text ))
397435
@@ -435,7 +473,23 @@ def __init__(
435473 server : str ,
436474 created : Optional [float ] = None ,
437475 ) -> None :
438- super ().__init__ (name , type_ , class_ , ttl , created )
476+ self ._fast_init (
477+ name , type_ , class_ , ttl , priority , weight , port , server , created or current_time_millis ()
478+ )
479+
480+ def _fast_init (
481+ self ,
482+ name : str ,
483+ type_ : _int ,
484+ class_ : _int ,
485+ ttl : _float ,
486+ priority : _int ,
487+ weight : _int ,
488+ port : _int ,
489+ server : str ,
490+ created : _float ,
491+ ) -> None :
492+ self ._fast_init_record (name , type_ , class_ , ttl , created )
439493 self .priority = priority
440494 self .weight = weight
441495 self .port = port
@@ -483,12 +537,24 @@ def __init__(
483537 name : str ,
484538 type_ : int ,
485539 class_ : int ,
486- ttl : int ,
540+ ttl : Union [ int , float ] ,
487541 next_name : str ,
488542 rdtypes : List [int ],
489543 created : Optional [float ] = None ,
490544 ) -> None :
491- super ().__init__ (name , type_ , class_ , ttl , created )
545+ self ._fast_init (name , type_ , class_ , ttl , next_name , rdtypes , created or current_time_millis ())
546+
547+ def _fast_init (
548+ self ,
549+ name : str ,
550+ type_ : _int ,
551+ class_ : _int ,
552+ ttl : _float ,
553+ next_name : str ,
554+ rdtypes : List [_int ],
555+ created : _float ,
556+ ) -> None :
557+ self ._fast_init_record (name , type_ , class_ , ttl , created )
492558 self .next_name = next_name
493559 self .rdtypes = sorted (rdtypes )
494560 self ._hash = hash ((self .key , type_ , self .class_ , next_name , * self .rdtypes ))
0 commit comments