[feedback] More efficient userspace impl for uMC
Lauren Tan committed
Oct 31, 2023 at 13:17 UTC
776f2148b441bafb72f19c83b4834dcf33a2a1d0
1 file changed
+7
-5
compiler/packages/sprout/src/shared-runtime.ts
+7
-5
@@ -195,9 +195,11 @@ export const ObjectWithHooks = {
195
const $empty = Symbol.for("react.memo_cache_sentinel");
196
export function unstable_useMemoCache(size: number) {
197
"use no forget";
198
- const $ = new Array(size);
199
- for (let ii = 0; ii < size; ii++) {
200
- $[ii] = $empty;
201
- }
202
- return React.useRef($).current;
198
+ return React.useState(() => {
199
+ const $ = new Array(size);
200
+ for (let ii = 0; ii < size; ii++) {
201
+ $[ii] = $empty;
202
+ }
203
+ return $;
204
+ })[0];
205
}