From 81d5f08100fa29f7749cf60cf04792a89a772211 Mon Sep 17 00:00:00 2001 From: Nicolas Dandrimont Date: Thu, 26 Dec 2013 03:00:24 +0100 Subject: [PATCH] Only call macroexpand when needed We only need to call macroexpand on HyExpressions, as this is already guarded in macroexpand_1. This saves us a few funcalls. --- hy/compiler.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hy/compiler.py b/hy/compiler.py index 36dd12a..0c73027 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -420,7 +420,6 @@ class HyASTCompiler(object): def compile(self, tree): try: - tree = macroexpand(tree, self.module_name) _type = type(tree) ret = self.compile_atom(_type, tree) if ret: @@ -1497,6 +1496,13 @@ class HyASTCompiler(object): def compile_expression(self, expression): if expression == []: return self.compile_list(expression) + + # Perform macro expansions + expression = macroexpand(expression, self.module_name) + if not isinstance(expression, HyExpression): + # Go through compile again if the type changed. + return self.compile(expression) + fn = expression[0] func = None if isinstance(fn, HyKeyword):