@@ -149,8 +149,12 @@ def __init__(self, identifier: str) -> None:
149149 assert len (identifier ) != 0
150150 self .identifier = identifier
151151
152- def __eq__ (self , other : Any ) -> bool :
153- return type (other ) is ASTIdentifier and self .identifier == other .identifier
152+ # ASTBaseBase already implements this method,
153+ # but specialising it here improves performance
154+ def __eq__ (self , other : object ) -> bool :
155+ if type (other ) is not ASTIdentifier :
156+ return NotImplemented
157+ return self .identifier == other .identifier
154158
155159 def is_anon (self ) -> bool :
156160 return self .identifier [0 ] == '@'
@@ -1448,6 +1452,10 @@ def __init__(self, objectType: str, directiveType: str | None,
14481452 # set by CObject._add_enumerator_to_parent
14491453 self .enumeratorScopedSymbol : Symbol | None = None
14501454
1455+ # the cache assumes that by the time get_newest_id is called, no
1456+ # further changes will be made to this object
1457+ self ._newest_id_cache : str | None = None
1458+
14511459 def clone (self ) -> ASTDeclaration :
14521460 return ASTDeclaration (self .objectType , self .directiveType ,
14531461 self .declaration .clone (), self .semicolon )
@@ -1474,7 +1482,9 @@ def get_id(self, version: int, prefixed: bool = True) -> str:
14741482 return id_
14751483
14761484 def get_newest_id (self ) -> str :
1477- return self .get_id (_max_id , True )
1485+ if self ._newest_id_cache is None :
1486+ self ._newest_id_cache = self .get_id (_max_id , True )
1487+ return self ._newest_id_cache
14781488
14791489 def _stringify (self , transform : StringifyTransform ) -> str :
14801490 res = transform (self .declaration )
0 commit comments