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:
Lauren Tan
2022-10-17 16:07:50 -04:00
parent 90e189ae82
commit b03752cbe0
+8 -3
View File
@@ -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() {