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 0b368b7 commit 0893cab
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/canmatrix/canmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,7 @@ def frame_by_id(self, arbitration_id): # type: (ArbitrationId) -> typing.Union[
:rtype: Frame or None
"""
hash_name = f"{arbitration_id.id}_{arbitration_id.extended}"

frame = self._frames_dict_id_extend.get(hash_name, None)
if frame is not None:
return frame
Expand Down Expand Up @@ -2095,7 +2096,7 @@ def add_frame(self, frame): # type: (Frame) -> Frame
:return: the inserted Frame
"""
self.frames.append(frame)

self._frames_dict_id_extend = {}
self.frames_dict_name[frame.name] = frame
if frame.header_id:
self.frames_dict_id[frame.header_id] = frame
Expand All @@ -2110,6 +2111,7 @@ def remove_frame(self, frame): # type: (Frame) -> None
:param Frame frame: frame to remove from CAN Matrix
"""
self.frames.remove(frame)
self._frames_dict_id_extend = {}

def add_signal(self, signal): # type: (Signal) -> Signal
"""
Expand Down Expand Up @@ -2204,6 +2206,8 @@ def add_ecu(self, ecu): # type(Ecu) -> None # todo return Ecu?
if bu.name.strip() == ecu.name:
return
self.ecus.append(ecu)
self._frames_dict_id_extend = {}


def del_ecu(self, ecu_or_glob): # type: (typing.Union[Ecu, str]) -> None
"""Remove ECU from Matrix and all Frames.
Expand Down Expand Up @@ -2374,6 +2378,7 @@ def merge(self, mergeArray): # type: (typing.Sequence[CanMatrix]) -> None
else:
logger.error(
"Name Conflict, could not copy/merge EnvVar " + envVar)
self._frames_dict_id_extend = {}

def set_fd_type(self) -> None:
"""Try to guess and set the CAN type for every frame.
Expand Down

0 comments on commit 0893cab

Please sign in to comment.