From 9f5cd2e425fdb8e89531a5a89ade539b7d79a517 Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Sun, 14 Dec 2014 15:56:15 -0800 Subject: [PATCH] Speed up run() by caching in local variables --- py65/monitor.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/py65/monitor.py b/py65/monitor.py index 98ad997..99a7d68 100644 --- a/py65/monitor.py +++ b/py65/monitor.py @@ -439,17 +439,19 @@ class Monitor(cmd.Cmd): def _run(self, stopcodes): stopcodes = set(stopcodes) breakpoints = set(self._breakpoints) + mpu = self._mpu + mem = self._mpu.memory - if not breakpoints: # optimization + if not breakpoints: while True: - self._mpu.step() - if self._mpu.memory[self._mpu.pc] in stopcodes: + mpu.step() + if mem[mpu.pc] in stopcodes: break else: while True: - self._mpu.step() - pc = self._mpu.pc - if self._mpu.memory[pc] in stopcodes: + mpu.step() + pc = mpu.pc + if mem[pc] in stopcodes: break if pc in breakpoints: msg = "Breakpoint %d reached."