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

Commit cea3011

Browse files
committed
WIP: fixes for expression caching
1 parent 73530d1 commit cea3011

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

src/ng/parse.js

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,8 +1052,7 @@ function $ParseProvider() {
10521052
parsedExpression = wrapSharedExpression(parsedExpression);
10531053
parsedExpression.$$watchDelegate = parsedExpression.literal ?
10541054
oneTimeLiteralWatchDelegate : oneTimeWatchDelegate;
1055-
}
1056-
else if (parsedExpression.inputs) {
1055+
} else if (parsedExpression.inputs) {
10571056
parsedExpression.$$watchDelegate = inputsWatchDelegate;
10581057
}
10591058

@@ -1075,8 +1074,7 @@ function $ParseProvider() {
10751074
if (!input.constant) {
10761075
if (input.inputs) {
10771076
collectExpressionInputs(input.inputs, list);
1078-
}
1079-
else if (-1 === list.indexOf(input)) {
1077+
} else if (list.indexOf(input) === -1) { // TODO(perf) can we do better?
10801078
list.push(input);
10811079
}
10821080
}
@@ -1089,21 +1087,18 @@ function $ParseProvider() {
10891087
if (o1 == null || o2 == null) return o1 === o2; // null/undefined
10901088

10911089
if (typeof o1 === "object") {
1092-
//The same object is not supported because it may have been mutated
1090+
// The same object is not supported because it may have been mutated
10931091
if (o1 === o2) return false;
10941092

10951093
if (typeof o2 !== "object") return false;
10961094

1097-
//Dates
1098-
if (isDate(o1) && isDate(o2)) {
1095+
// Dates
1096+
if (isDate(o1) && isDate(o2)) { // TODO(perf): make this more generic via valueOf
10991097
o1 = o1.getTime();
11001098
o2 = o2.getTime();
1101-
1102-
//Fallthru to the primitive equality check
1103-
}
1104-
1105-
//Otherwise objects are not supported - recursing over arrays/object would be too expensive
1106-
else {
1099+
// Fallthru to the primitive equality check
1100+
} else {
1101+
// objects/arrays are not supported - deep-watching them would be too expensive
11071102
return false;
11081103
}
11091104
}
@@ -1116,29 +1111,33 @@ function $ParseProvider() {
11161111
var inputExpressions = parsedExpression.$$inputs ||
11171112
(parsedExpression.$$inputs = collectExpressionInputs(parsedExpression.inputs, []));
11181113

1119-
var inputs = [simpleEquals/*=something that will never equal an evaluated input*/];
11201114
var lastResult;
11211115

1122-
if (1 === inputExpressions.length) {
1123-
inputs = inputs[0];
1116+
if (inputExpressions.length === 1) {
1117+
var oldInputValue = simpleEquals; // init to something unique so that equals check fails
11241118
inputExpressions = inputExpressions[0];
11251119
return scope.$watch(function expressionInputWatch(scope) {
1126-
var newVal = inputExpressions(scope);
1127-
if (!simpleEquals(newVal, inputs)) {
1120+
var newInputValue = inputExpressions(scope);
1121+
if (!simpleEquals(newInputValue, oldInputValue)) {
11281122
lastResult = parsedExpression(scope);
1129-
inputs = newVal;
1123+
oldInputValue = newInputValue;
11301124
}
11311125
return lastResult;
11321126
}, listener, objectEquality);
11331127
}
11341128

1129+
var oldInputValues = [];
1130+
for (var i = 0, ii = inputExpressions.length; i < ii; i++) {
1131+
oldInputValues[i] = simpleEquals; // init to something unique so that equals check fails
1132+
}
1133+
11351134
return scope.$watch(function expressionInputsWatch(scope) {
11361135
var changed = false;
11371136

1138-
for (var i=0, ii=inputExpressions.length; i<ii; i++) {
1139-
var valI = inputExpressions[i](scope);
1140-
if (changed || (changed = !simpleEquals(valI, inputs[i]))) {
1141-
inputs[i] = valI;
1137+
for (var i = 0, ii = inputExpressions.length; i < ii; i++) {
1138+
var newInputValue = inputExpressions[i](scope);
1139+
if (changed || (changed = !simpleEquals(newInputValue, oldInputValues[i]))) {
1140+
oldInputValues[i] = newInputValue;
11421141
}
11431142
}
11441143

0 commit comments

Comments
 (0)