shithub: pokecrystal

Download patch

ref: 473bd192d9eb5767d5cda2ae21a0aa52552fabf6
parent: 7eaf5bf72656fa84d2aa94a0ea6e534120f40131
author: Bryan Bishop <kanzure@gmail.com>
date: Sat Aug 31 07:57:01 EDT 2013

better read_line performance in preprocessor

Jump out of read_line early if the line is an empty string or a newline.

--- a/preprocessor.py
+++ b/preprocessor.py
@@ -427,13 +427,11 @@
     token = extract_token(asm)
 
     # skip db and dw since rgbasm handles those and they aren't macros
-    if token not in ["db", "dw"]:
-        # check against all names
-        if token in macro_table:
-            return (macro_table[token], token)
+    if token is not None and token not in ["db", "dw"] and token in macro_table:
+        return (macro_table[token], token)
+    else:
+        return (None, None)
 
-    return (None, None)
-
 def is_based_on(something, base):
     """
     Checks whether or not 'something' is a class that is a subclass of a class
@@ -611,6 +609,10 @@
 def read_line(l, macro_table):
     """Preprocesses a given line of asm."""
 
+    if l in ["\n", ""]:
+        sys.stdout.write(l)
+        return # jump out early
+
     # strip comments from asm
     asm, comment = separate_comment(l)
 
@@ -624,7 +626,7 @@
         sys.stdout.write(asm)
 
     # ascii string macro preserves the bytes as ascii (skip the translator)
-    elif len(asm) > 6 and "ascii " == asm[:6] or "\tascii " == asm[:7]:
+    elif len(asm) > 6 and ("ascii " == asm[:6] or "\tascii " == asm[:7]):
         asm = asm.replace("ascii", "db", 1)
         sys.stdout.write(asm)
 
@@ -640,7 +642,8 @@
         else:
             sys.stdout.write(asm)
 
-    if comment: sys.stdout.write(comment)
+    if comment:
+        sys.stdout.write(comment)
 
 def preprocess(macro_table, lines=None):
     """Main entry point for the preprocessor."""
--