Commit 02dff7f
committed
Avoid unnecesary prototype loop
## Background
People at redux-toolkit copy/pasted this utility in there, and [they are not welcoming a PR](reduxjs/redux-toolkit#581) because of that, but the `while` loop in here is completely unnecessary, as the comparison is made on the first `proto` only.
## Improvements
* _O(1)_ instead of _O(n)_
* safe fallback for `Object.create(null)` cases
* fast lane for `new Class()` derived objects
* better performance
* smaller code size
As this change has zero downsides, unless I am missing some explicit reason to `while` loop instead of never using `getPrototypeOf` more than twice, I hope it'll get in, so that others might copy and paste this new version.
Best Regards.1 parent 7bf8b06 commit 02dff7f
1 file changed
+5
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
14 | 11 | | |
0 commit comments