Skip to content

Commit

Permalink
cache short_names for spead up parsing (#801)
Browse files Browse the repository at this point in the history
Co-authored-by: Eduard Bröcker <[email protected]>
  • Loading branch information
ebroecker and Eduard Bröcker authored Jun 21, 2024
1 parent a590f38 commit dbc96d9
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/canmatrix/formats/arxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ class Earxml:
def __init__(self):
self.xml_element_cache = dict() # type: typing.Dict[str, _Element]
self.path_cache = {}
self.sn_cache = {}

def fill_caches(self, start_element=None, ar_path=""):
if start_element is None:
start_element = self.root
self.path_cache = {}
if start_element.tag == self.ns + "SHORT-NAME":
self.sn_cache[start_element.getparent()] = start_element.text
return start_element.text
for sub_element in start_element:
text = sub_element.text
Expand Down Expand Up @@ -155,13 +157,8 @@ def get_short_name_path(self, shortname_path):
def get_short_name(self, element):
# type: (_Element, str) -> str
"""Get element short name."""
if element is None:
return ""
name = element.find('./' + self.ns + 'SHORT-NAME')
if name is not None and name.text is not None:
return name.text
return ""

return self.sn_cache.get(element, "")

def follow_ref(self, start_element, element_name):
ref_element = self.find(element_name, start_element)
if ref_element is None:
Expand Down

0 comments on commit dbc96d9

Please sign in to comment.