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

Commit

Permalink
perf(interpolate): 20%. Cache the interpolated expressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbdeboer authored and [email protected] committed May 17, 2014
1 parent a1d67aa commit 669d47c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/core/interpolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ part of angular.core_internal;
*/
@Injectable()
class Interpolate implements Function {
var _cache = {};
/**
* Compiles markup text into expression.
*
Expand All @@ -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;
Expand Down

0 comments on commit 669d47c

Please sign in to comment.