diff options
author | German M. Bravo <german.mb@deipi.com> | 2013-08-17 17:54:19 -0500 |
---|---|---|
committer | German M. Bravo <german.mb@deipi.com> | 2013-08-17 17:54:19 -0500 |
commit | e340ad421b7e2bdc391acb9ddca5a5ae6309c7bc (patch) | |
tree | df0608a1f5b0d6fdcd4caa8590f13b1570e24400 | |
parent | 42884618361420e02ad27f95a9fa3dfbc7ad14a7 (diff) | |
download | pyscss-e340ad421b7e2bdc391acb9ddca5a5ae6309c7bc.tar.gz |
AST cache is in a per-target basis (also, cache is now in the Calculator class type
-rw-r--r-- | scss/expression.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/scss/expression.py b/scss/expression.py index 0b55b0e..7dc1f71 100644 --- a/scss/expression.py +++ b/scss/expression.py @@ -24,7 +24,6 @@ except ImportError: log = logging.getLogger(__name__) FATAL_UNDEFINED = True -ast_cache = {} class Calculator(object): @@ -115,10 +114,18 @@ class Calculator(object): value = _vi return value + def get_ast_cache(self, target): + if not hasattr(self, 'ast_cache'): + self.__class__.ast_cache = {} + if target not in self.ast_cache: + self.ast_cache[target] = {} + return self.ast_cache[target] + def evaluate_expression(self, expr, divide=False): if not isinstance(expr, six.string_types): raise TypeError("Expected string, got %r" % (expr,)) + ast_cache = self.get_ast_cache('goal') if expr in ast_cache: ast = ast_cache[expr] @@ -147,14 +154,14 @@ class Calculator(object): return None def parse_expression(self, expr, target='goal'): + ast_cache = self.get_ast_cache(target) if expr in ast_cache: return ast_cache[expr] parser = SassExpression(SassExpressionScanner(expr)) ast = getattr(parser, target)() - if target == 'goal': - ast_cache[expr] = ast + ast_cache[expr] = ast return ast |