@samitouri / QOS-React-2 / commits / d44bf272ad

Refactor: materialize typed array in one place

Dan Abramov committed Apr 18, 2019 at 20:02 UTC d44bf272ad1ffb9adfd21de760645840ffdaec86
1 file changed +6 -5
src/backend/renderer.js
+6 -5
@@ -574,7 +574,7 @@ export function attach(
574 }
575
576 let pendingOperations: Array<number> = [];
577 - let pendingOperationsQueue: Array<Array<number>> | null = [];
577 + let pendingOperationsQueue: Array<Uint32Array> | null = [];
578
579 let nextOperation: Array<number> = [];
580 function beginNextOperation(size: number): void {
@@ -624,14 +624,15 @@ export function attach(
624 // Let the frontend know about tree operations.
625 // The first value in this array will identify which root it corresponds to,
626 // so we do no longer need to dispatch a separate root-committed event.
627 + const ops = Uint32Array.from(pendingOperations);
628 if (pendingOperationsQueue !== null) {
629 // Until the frontend has been connected, store the tree operations.
630 // This will let us avoid walking the tree later when the frontend connects,
631 // and it enables the Profiler's reload-and-profile functionality to work as well.
631 - pendingOperationsQueue.push(pendingOperations);
632 + pendingOperationsQueue.push(ops);
633 } else {
634 // If we've already connected to the frontend, just pass the operations through.
634 - hook.emit('operations', Uint32Array.from(pendingOperations));
635 + hook.emit('operations', ops);
636 }
637
638 pendingOperations = [];
@@ -1058,8 +1059,8 @@ export function attach(
1059 ) {
1060 // We may have already queued up some operations before the frontend connected
1061 // If so, let the frontend know about them.
1061 - localPendingOperationsQueue.forEach(pendingOperations => {
1062 - hook.emit('operations', Uint32Array.from(pendingOperations));
1062 + localPendingOperationsQueue.forEach(ops => {
1063 + hook.emit('operations', ops);
1064 });
1065 } else {
1066 // If we have not been profiling, then we can just walk the tree and build up its current state as-is.