@@ -254,8 +254,14 @@ class Scope {
254
254
}
255
255
}
256
256
257
- AST ast = rootScope._astParser (expression,
258
- formatters: formatters, collection: collection);
257
+ String astKey =
258
+ "${collection ? "C" : "." }${formatters == null ? "." : formatters .hashCode }$expression " ;
259
+ AST ast = rootScope.astCache[astKey];
260
+ if (ast == null ) {
261
+ ast = rootScope.astCache[astKey] =
262
+ rootScope._astParser (expression,
263
+ formatters: formatters, collection: collection);
264
+ }
259
265
260
266
return watch = watchAST (ast, fn, canChangeModel: canChangeModel);
261
267
}
@@ -568,6 +574,9 @@ class RootScope extends Scope {
568
574
final ScopeDigestTTL _ttl;
569
575
final VmTurnZone _zone;
570
576
577
+ // For Scope.watch().
578
+ final Map <String , AST > astCache = new HashMap <String , AST >();
579
+
571
580
_FunctionChain _runAsyncHead, _runAsyncTail;
572
581
_FunctionChain _domWriteHead, _domWriteTail;
573
582
_FunctionChain _domReadHead, _domReadTail;
@@ -629,7 +638,7 @@ class RootScope extends Scope {
629
638
630
639
RootScope (Object context, Parser parser, ASTParser astParser,
631
640
FieldGetterFactory fieldGetterFactory, FormatterMap formatters, this ._exceptionHandler,
632
- ScopeDigestTTL ttl, this ._zone, ScopeStats _scopeStats)
641
+ ScopeDigestTTL ttl, this ._zone, ScopeStats _scopeStats, CacheRegister cacheRegister )
633
642
: _scopeStats = _scopeStats,
634
643
_ttl = ttl,
635
644
_parser = parser,
@@ -650,6 +659,7 @@ class RootScope extends Scope {
650
659
for (num i = 0 ; i <= _ttl.ttl; i++ ) {
651
660
_digestTags.add (new UserTag ('NgDigest${i }' ));
652
661
}
662
+ cacheRegister.registerCache ("ScopeWatchASTs" , astCache);
653
663
}
654
664
655
665
RootScope get rootScope => this ;
0 commit comments