mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-16 21:24:59 +08:00
improve algo by skipping an O(n) operation
This commit is contained in:
parent
d4df9e731d
commit
32cca0534c
@ -89,9 +89,10 @@ export function objectHasDiff<O extends {}>(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]);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user