Skip to content

Commit f4cbe51

Browse files
committed
Switch to itertools chaining from repeated updates in concatenate follow
1 parent e56ff56 commit f4cbe51

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

interegular/fsm.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,17 @@ def follow(current, new_transition):
350350
next FSM if we reach the end of the current one
351351
TODO: improve all follow() implementations to allow for dead metastates?
352352
"""
353-
next_states = set()
354-
for (i, substate) in current:
355-
fsm = fsms[i]
356-
current_vertex: TransitionKey = new_to_old[i][new_transition]
357-
if substate in fsm.map and current_vertex in fsm.map[substate]:
358-
next_states.update(connect_all(i, fsm.map[substate][current_vertex]))
353+
def next_states():
354+
for (i, substate) in current:
355+
fsm = fsms[i]
356+
current_vertex: TransitionKey = new_to_old[i][new_transition]
357+
if substate in fsm.map and current_vertex in fsm.map[substate]:
358+
yield connect_all(i, fsm.map[substate][current_vertex])
359+
360+
next_states_set = frozenset(chain.from_iterable(next_states()))
359361
if not next_states:
360362
raise OblivionError
361-
return frozenset(next_states)
363+
return next_states_set
362364

363365
return crawl(alphabet, initial, final, follow)
364366

0 commit comments

Comments
 (0)