From 1586b1808dc99386b0a77a9489ada6dac79e3e87 Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Sun, 14 Dec 2014 14:35:40 -0800 Subject: [PATCH] Speed up run() by using sets for stopcodes and breakpoints --- py65/monitor.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/py65/monitor.py b/py65/monitor.py index 9483bdd..98ad997 100644 --- a/py65/monitor.py +++ b/py65/monitor.py @@ -436,22 +436,25 @@ class Monitor(cmd.Cmd): brks = [0x00] # BRK self._run(stopcodes=brks) - def _run(self, stopcodes=[]): - last_instruct = None - if not self._breakpoints: - while last_instruct not in stopcodes: + def _run(self, stopcodes): + stopcodes = set(stopcodes) + breakpoints = set(self._breakpoints) + + if not breakpoints: # optimization + while True: self._mpu.step() - last_instruct = self._mpu.memory[self._mpu.pc] + if self._mpu.memory[self._mpu.pc] in stopcodes: + break else: - # Slows things down quite a bit, unfortunately. - breakpoint = False - while last_instruct not in stopcodes and not breakpoint: + while True: self._mpu.step() - last_instruct = self._mpu.memory[self._mpu.pc] - if self._mpu.pc in self._breakpoints: + pc = self._mpu.pc + if self._mpu.memory[pc] in stopcodes: + break + if pc in breakpoints: msg = "Breakpoint %d reached." - self._output(msg % self._breakpoints.index(self._mpu.pc)) - breakpoint = True + self._output(msg % self._breakpoints.index(pc)) + break def help_radix(self): self._output("radix [H|D|O|B]")