Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

perf($rootScope): do not mark $watchCollectionInterceptor as $stateful #16009

Merged
merged 1 commit into from
Sep 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/ng/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1944,6 +1944,7 @@ function $ParseProvider() {
return second(first(value));
}
chainedInterceptor.$stateful = first.$stateful || second.$stateful;
chainedInterceptor.$$pure = first.$$pure && second.$$pure;

return chainedInterceptor;
}
Expand Down Expand Up @@ -1979,14 +1980,18 @@ function $ParseProvider() {
// If the expression itself has no inputs then use the full expression as an input.
if (!interceptorFn.$stateful) {
useInputs = !parsedExpression.inputs;
fn.inputs = (parsedExpression.inputs ? parsedExpression.inputs : [parsedExpression]).map(function(e) {
fn.inputs = parsedExpression.inputs ? parsedExpression.inputs : [parsedExpression];

if (!interceptorFn.$$pure) {
fn.inputs = fn.inputs.map(function(e) {
// Remove the isPure flag of inputs when it is not absolute because they are now wrapped in a
// potentially non-pure interceptor function.
// non-pure interceptor function.
if (e.isPure === PURITY_RELATIVE) {
return function depurifier(s) { return e(s); };
}
return e;
});
}
}

return addWatchDelegate(fn);
Expand Down
6 changes: 5 additions & 1 deletion src/ng/rootScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,11 @@ function $RootScopeProvider() {
* de-registration function is executed, the internal watch operation is terminated.
*/
$watchCollection: function(obj, listener) {
$watchCollectionInterceptor.$stateful = true;
// Mark the interceptor as
// ... $$pure when literal since the instance will change when any input changes
$watchCollectionInterceptor.$$pure = $parse(obj).literal;
// ... $stateful when non-literal since we must read the state of the collection
$watchCollectionInterceptor.$stateful = !$watchCollectionInterceptor.$$pure;

var self = this;
// the current value, updated on each dirty-check run
Expand Down