Skip to content

Commit

Permalink
speedup for frame_by_id
Browse files Browse the repository at this point in the history
  • Loading branch information
ebroecker committed Dec 18, 2024
1 parent 7fde135 commit 4743734
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/canmatrix/canmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,7 @@ class CanMatrix(object):

frames_dict_name = attr.ib(factory=dict) # type: typing.MutableSequence[Frame]
frames_dict_id = attr.ib(factory=dict) # type: typing.MutableSequence[Frame]

_frames_dict_id_extend = {}
signal_defines = attr.ib(factory=dict) # type: typing.MutableMapping[str, Define]
frame_defines = attr.ib(factory=dict) # type: typing.MutableMapping[str, Define]
global_defines = attr.ib(factory=dict) # type: typing.MutableMapping[str, Define]
Expand Down Expand Up @@ -1985,10 +1985,15 @@ def frame_by_id(self, arbitration_id): # type: (ArbitrationId) -> typing.Union[
:param ArbitrationId arbitration_id: Frame id as canmatrix.ArbitrationId
:rtype: Frame or None
"""
for test in self.frames:
if test.arbitration_id == arbitration_id:
hash_name = f"{arbitration_id.id}_{arbitration_id.extended}"
frame = self._frames_dict_id_extend.get(hash_name)
if frame is not None:
return frame
for frame in self.frames:
if frame.arbitration_id == arbitration_id:
# found ID while ignoring extended or standard
return test
self._frames_dict_id_extend[hash_name] = frame
return frame
return None

def frame_by_header_id(self, header_id): # type: (HeaderId) -> typing.Union[Frame, None]
Expand Down

0 comments on commit 4743734

Please sign in to comment.