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

Commit 32cca05

Browse files
committed
improve algo by skipping an O(n) operation
1 parent d4df9e7 commit 32cca05

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/utils/objects.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ export function objectHasDiff<O extends {}>(a: O, b: O): boolean {
8989
if (a === b) return false;
9090
const aKeys = Object.keys(a);
9191
const bKeys = Object.keys(b);
92-
if (arrayHasDiff(aKeys, bKeys)) return true;
93-
9492
const possibleChanges = arrayUnion(aKeys, bKeys);
93+
// if the amalgamation of both sets of keys has the a different length to the inputs then there must be a change
94+
if (possibleChanges.length !== aKeys.length) return true;
95+
9596
return possibleChanges.some(k => a[k] !== b[k]);
9697
}
9798

0 commit comments

Comments
 (0)