Skip to content

Commit e95860d

Browse files
committed
perf($compile): caching $interpolate operations on isolated scope @ properties
1 parent 222b9ac commit e95860d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/ng/compile.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,19 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
15221522
linkFn,
15231523
directiveValue;
15241524

1525+
// Helper/cache to $interpolate + evaluate a string while caching each $interpolate()
1526+
function runInterpolate(value, scope) {
1527+
var cache = runInterpolate.$$cache || (runInterpolate.$$cache = createMap());
1528+
var interped;
1529+
if (value in cache) {
1530+
interped = cache[value];
1531+
} else {
1532+
interped = cache[value] = $interpolate(value, true);
1533+
}
1534+
1535+
return interped ? interped(scope) : value;
1536+
}
1537+
15251538
// executes all directives on the current element
15261539
for (var i = 0, ii = directives.length; i < ii; i++) {
15271540
directive = directives[i];
@@ -1857,7 +1870,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
18571870
if (attrs[attrName]) {
18581871
// If the attribute has been provided then we trigger an interpolation to ensure
18591872
// the value is there for use in the link fn
1860-
isolateBindingContext[scopeName] = $interpolate(attrs[attrName])(scope);
1873+
isolateBindingContext[scopeName] = runInterpolate(attrs[attrName], scope);
18611874
}
18621875
break;
18631876

0 commit comments

Comments
 (0)