From 2f18dffe9ff79eba5ac8ec2d9de1facde62816f7 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 13 Dec 2018 18:34:44 +0000 Subject: [PATCH] back.pysim: collect handlers before running (-5% runtime). --- nmigen/back/pysim.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nmigen/back/pysim.py b/nmigen/back/pysim.py index 5b0f352..7dfda13 100644 --- a/nmigen/back/pysim.py +++ b/nmigen/back/pysim.py @@ -306,11 +306,14 @@ class Simulator: self._vcd_writer.change(vcd_signal, self._timestamp * 1e10, new.value) def _handle_event(self): + handlers = set() while self._state.curr_dirty: signal = self._state.curr_dirty.pop() if signal in self._handlers: - for handler in self._handlers[signal]: - handler(self._state) + handlers.update(self._handlers[signal]) + + for handler in handlers: + handler(self._state) for signal in self._state.next_dirty: if signal in self._comb_signals or signal in self._user_signals: -- 2.30.2