From d87b95bc1132f6f04595cbbf333dbba31f685be4 Mon Sep 17 00:00:00 2001 From: Rafael Weinstein Date: Thu, 22 Aug 2013 15:32:41 -0700 Subject: [PATCH] Cache expressions R=arv BUG= Review URL: https://codereview.appspot.com/12815048 --- src/polymer-expressions.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/polymer-expressions.js b/src/polymer-expressions.js index d5a1df9..7489ef7 100644 --- a/src/polymer-expressions.js +++ b/src/polymer-expressions.js @@ -125,11 +125,17 @@ return binding; } + // TODO(rafaelw): Implement simple LRU. + var expressionParseCache = {}; + function getExpressionBinding(model, expressionText) { try { - // TODO(rafaelw): Cache expressions. - var delegate = new ASTDelegate(); - esprima.parse(expressionText, delegate); + var delegate = expressionParseCache[expressionText]; + if (!delegate) { + delegate = new ASTDelegate(); + esprima.parse(expressionText, delegate); + expressionParseCache[expressionText] = delegate; + } if (!delegate.expression && !delegate.labeledStatements.length) return;