From 669d47ce8dd9c1df1033a7f0715be76843be67a3 Mon Sep 17 00:00:00 2001 From: James deBoer Date: Fri, 16 May 2014 18:14:29 -0700 Subject: [PATCH] perf(interpolate): 20%. Cache the interpolated expressions. --- lib/core/interpolate.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/core/interpolate.dart b/lib/core/interpolate.dart index aed34f53f..8c74a2c23 100644 --- a/lib/core/interpolate.dart +++ b/lib/core/interpolate.dart @@ -10,6 +10,7 @@ part of angular.core_internal; */ @Injectable() class Interpolate implements Function { + var _cache = {}; /** * Compiles markup text into expression. * @@ -23,6 +24,15 @@ class Interpolate implements Function { String call(String template, [bool mustHaveExpression = false, String startSymbol = '{{', String endSymbol = '}}']) { + if (mustHaveExpression == false && startSymbol == '{{' && endSymbol == '}}') { + // cachable + return _cache.putIfAbsent(template, () => _call(template, mustHaveExpression, startSymbol, endSymbol)); + } + return _call(template, mustHaveExpression, startSymbol, endSymbol); + } + + String _call(String template, [bool mustHaveExpression = false, + String startSymbol, String endSymbol]) { if (template == null || template.isEmpty) return ""; final startLen = startSymbol.length;