Skip to content

Commit

Permalink
Activable transitions are only computed once in _select_transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreDecan committed Jun 15, 2018
1 parent 36afa42 commit ddeff5f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions sismic/interpreter/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,22 +368,26 @@ def _select_transitions(self) -> Tuple[Optional[Event], List[Transition]]:
"""
transitions = []

# Select transitions with no event first
for transition in self._statechart.transitions:
if (transition.event is None and transition.source in self._configuration and
# Transitions of active states
activable_transitions = [tr for tr in self._statechart.transitions if tr.source in self._configuration]

# Eventless transitions are considered first
for transition in activable_transitions:
if (transition.event is None and
(transition.guard is None or self._evaluator.evaluate_guard(transition))):
transitions.append(transition)

# If an eventless transition can be triggered, return it
if len(transitions) > 0:
return None, transitions

# Take and consume next event
# Otherwise, take and consume next event
event = self._select_event()
if event is None:
return None, []

for transition in self._statechart.transitions:
if (transition.event == getattr(event, 'name', None) and transition.source in self._configuration and
for transition in activable_transitions:
if (transition.event == event.name and
(transition.guard is None or self._evaluator.evaluate_guard(transition, event))):
transitions.append(transition)
return event, transitions
Expand Down

0 comments on commit ddeff5f

Please sign in to comment.