-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using for loop for improved speed (#59)
- Loading branch information
1 parent
cbde410
commit dc00d09
Showing
2 changed files
with
23 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// @flow | ||
export default function areInputsEqual( | ||
newInputs: mixed[], | ||
lastInputs: mixed[], | ||
) { | ||
// no checks needed if the inputs length has changed | ||
if (newInputs.length !== lastInputs.length) { | ||
return false; | ||
} | ||
// Using for loop for speed. It generally performs better than array.every | ||
// https://github.com/alexreardon/memoize-one/pull/59 | ||
|
||
for (let i = 0; i < newInputs.length; i++) { | ||
// using shallow equality check | ||
if (newInputs[i] !== lastInputs[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters