Skip to content

Commit 222b9ac

Browse files
committed
perf($compile): only re-$interpolate attributes values if the value has changed
1 parent 74123e8 commit 222b9ac

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/ng/compile.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -2273,7 +2273,10 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
22732273

22742274

22752275
function addAttrInterpolateDirective(node, directives, value, name, allOrNothing) {
2276-
var interpolateFn = $interpolate(value, true);
2276+
var trustedContext = getTrustedContext(node, name);
2277+
allOrNothing = ALL_OR_NOTHING_ATTRS[name] || allOrNothing;
2278+
2279+
var interpolateFn = $interpolate(value, true, trustedContext, allOrNothing);
22772280

22782281
// no interpolation found -> ignore
22792282
if (!interpolateFn) return;
@@ -2298,19 +2301,21 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
22982301
pre: function attrInterpolatePreLinkFn(scope, element, attr) {
22992302
var $$observers = (attr.$$observers || (attr.$$observers = {}));
23002303

2301-
// If the attribute was removed, then we are done
2302-
if (!attr[name]) {
2303-
return;
2304-
}
2304+
// If the attribute has changed since compilation
2305+
if (attr[name] !== value) {
2306+
// If the attribute was removed, then we are done
2307+
if (!attr[name]) {
2308+
return;
2309+
}
23052310

2306-
// we need to interpolate again, in case the attribute value has been updated
2307-
// (e.g. by another directive's compile function)
2308-
interpolateFn = $interpolate(attr[name], true, getTrustedContext(node, name),
2309-
ALL_OR_NOTHING_ATTRS[name] || allOrNothing);
2311+
// we need to interpolate again, in case the attribute value has been updated
2312+
// (e.g. by another directive's compile function)
2313+
interpolateFn = $interpolate(value = attr[name], true, trustedContext, allOrNothing);
23102314

2311-
// if attribute was updated so that there is no interpolation going on we don't want to
2312-
// register any observers
2313-
if (!interpolateFn) return;
2315+
// if attribute was updated so that there is no interpolation going on we don't want to
2316+
// register any observers
2317+
if (!interpolateFn) return;
2318+
}
23142319

23152320
// initialize attr object so that it's ready in case we need the value for isolate
23162321
// scope initialization, otherwise the value would not be available from isolate

0 commit comments

Comments
 (0)