Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 669d47c

Browse files
jbdeboertravis@travis-ci.org
authored andcommitted
perf(interpolate): 20%. Cache the interpolated expressions.
1 parent a1d67aa commit 669d47c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/core/interpolate.dart

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ part of angular.core_internal;
1010
*/
1111
@Injectable()
1212
class Interpolate implements Function {
13+
var _cache = {};
1314
/**
1415
* Compiles markup text into expression.
1516
*
@@ -23,6 +24,15 @@ class Interpolate implements Function {
2324

2425
String call(String template, [bool mustHaveExpression = false,
2526
String startSymbol = '{{', String endSymbol = '}}']) {
27+
if (mustHaveExpression == false && startSymbol == '{{' && endSymbol == '}}') {
28+
// cachable
29+
return _cache.putIfAbsent(template, () => _call(template, mustHaveExpression, startSymbol, endSymbol));
30+
}
31+
return _call(template, mustHaveExpression, startSymbol, endSymbol);
32+
}
33+
34+
String _call(String template, [bool mustHaveExpression = false,
35+
String startSymbol, String endSymbol]) {
2636
if (template == null || template.isEmpty) return "";
2737

2838
final startLen = startSymbol.length;

0 commit comments

Comments
 (0)