From 32cca0534c5ff7c7a86d854e6a00a4764652d20b Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 19 Feb 2021 00:15:00 +0000 Subject: [PATCH] improve algo by skipping an O(n) operation --- src/utils/objects.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utils/objects.ts b/src/utils/objects.ts index fe010df2b9..41e3f37d1b 100644 --- a/src/utils/objects.ts +++ b/src/utils/objects.ts @@ -89,9 +89,10 @@ export function objectHasDiff(a: O, b: O): boolean { if (a === b) return false; const aKeys = Object.keys(a); const bKeys = Object.keys(b); - if (arrayHasDiff(aKeys, bKeys)) return true; - const possibleChanges = arrayUnion(aKeys, bKeys); + // if the amalgamation of both sets of keys has the a different length to the inputs then there must be a change + if (possibleChanges.length !== aKeys.length) return true; + return possibleChanges.some(k => a[k] !== b[k]); }