mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Use for loop instead of Array.prototype.fill
Some prior [microbenchmarking](https://jsbench.me/7ol98ws520/1) showed that a for loop outperformed `fill` (which is about ~60% slower). This is the same approach we use in the latest useMemoCache PR
This commit is contained in:
+8
-3
@@ -16,9 +16,12 @@ const {
|
||||
|
||||
export const $empty = Symbol.for("react.usememocache_sentinel");
|
||||
|
||||
export function unstable_useMemoCache(i) {
|
||||
export function unstable_useMemoCache(size) {
|
||||
"use no forget";
|
||||
const $ = new Array(i).fill($empty);
|
||||
const $ = new Array(size);
|
||||
for (let ii = 0; ii < size; ii++) {
|
||||
$[ii] = $empty;
|
||||
}
|
||||
return useRef($).current;
|
||||
}
|
||||
|
||||
@@ -78,7 +81,9 @@ export function $endLazy() {
|
||||
}
|
||||
|
||||
export function $reset($) {
|
||||
$.fill($empty);
|
||||
for (let ii = 0; ii < $.length; ii++) {
|
||||
$[ii] = $empty;
|
||||
}
|
||||
}
|
||||
|
||||
export function $makeReadOnly() {
|
||||
|
||||
Reference in New Issue
Block a user