summaryrefslogtreecommitdiff
path: root/preprocessor.py
diff options
context:
space:
mode:
authorBryan Bishop <kanzure@gmail.com>2013-01-10 15:15:59 -0600
committerBryan Bishop <kanzure@gmail.com>2013-01-10 15:19:56 -0600
commitf2fd544e20a54aece3bb1699e2b4c6a5ff0d4078 (patch)
tree5b6d09459f7690bde4d46297f4f04d9cfe9f0d5c /preprocessor.py
parent3f9552910236021499a60c622b708ffb2ca1c43b (diff)
make the preprocessor a little faster
This reduced the preprocessing time from 8s to 2.7s.
Diffstat (limited to 'preprocessor.py')
-rw-r--r--preprocessor.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/preprocessor.py b/preprocessor.py
index 6b659443b..abb672822 100644
--- a/preprocessor.py
+++ b/preprocessor.py
@@ -393,6 +393,10 @@ def extract_token(asm):
token = asm.split(" ")[0].replace("\t", "").replace("\n", "")
return token
+def make_macro_table():
+ return dict([(macro.macro_name, macro) for macro in macros])
+macro_table = make_macro_table()
+
def macro_test(asm):
""" Returns a matching macro, or None/False.
"""
@@ -401,11 +405,10 @@ def macro_test(asm):
token = extract_token(asm)
# check against all names
- for macro in macros:
- if macro.macro_name == token:
- return macro, token
-
- return None, None
+ try:
+ return (macro_table[token], token)
+ except:
+ return (None, None)
def macro_translator(macro, token, line):
""" Converts a line with a macro into a rgbasm-compatible line.