minor performance improvement in _get_loaded_substates

This commit is contained in:
Benedikt Bartscher 2024-12-14 12:30:42 +01:00
parent 19d6e69913
commit 71adc178fc
No known key found for this signature in database

View File

@ -1499,20 +1499,21 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
""" """
root_state = self._get_root_state() root_state = self._get_root_state()
d = {root_state.get_full_name(): root_state} d = {root_state.get_full_name(): root_state}
d.update(root_state._get_loaded_substates()) root_state._get_loaded_substates(d)
return d return d
def _get_loaded_substates(self) -> dict[str, BaseState]: def _get_loaded_substates(
self,
loaded_substates: dict[str, BaseState],
) -> None:
"""Get all loaded substates of this state. """Get all loaded substates of this state.
Returns: Args:
A list of all loaded substates of this state. loaded_substates: A dictionary of loaded substates which will be updated with the substates of this state.
""" """
loaded_substates = {}
for substate in self.substates.values(): for substate in self.substates.values():
loaded_substates[substate.get_full_name()] = substate loaded_substates[substate.get_full_name()] = substate
loaded_substates.update(substate._get_loaded_substates()) substate._get_loaded_substates(loaded_substates)
return loaded_substates
def _get_root_state(self) -> BaseState: def _get_root_state(self) -> BaseState:
"""Get the root state of the state tree. """Get the root state of the state tree.