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

Commit f6ade7d

Browse files
committed
perf($parse): use valueOf to convert objects to primitives if possible
1 parent f87fa0a commit f6ade7d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/ng/parse.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,20 +1087,20 @@ function $ParseProvider() {
10871087
if (o1 == null || o2 == null) return o1 === o2; // null/undefined
10881088

10891089
if (typeof o1 === "object") {
1090-
// The same object is not supported because it may have been mutated
1091-
if (o1 === o2) return false;
10921090

1093-
if (typeof o2 !== "object") return false;
1091+
// attempt to convert the value to a primitive type
1092+
// TODO(docs): add a note to docs that by implementing valueOf even objects and arrays can
1093+
// be cheaply dirty-checked
1094+
o1 = o1.valueOf();
10941095

1095-
// Dates
1096-
if (isDate(o1) && isDate(o2)) { // TODO(perf): make this more generic via valueOf
1097-
o1 = o1.getTime();
1098-
o2 = o2.getTime();
1099-
// Fallthru to the primitive equality check
1100-
} else {
1096+
if (typeof o1 === "object") {
11011097
// objects/arrays are not supported - deep-watching them would be too expensive
11021098
return false;
11031099
}
1100+
1101+
o2 = o2.valueOf();
1102+
1103+
// fall-through to the primitive equality check
11041104
}
11051105

11061106
//Primitive or NaN

0 commit comments

Comments
 (0)