@samitouri / QOS-React-2 / commits / 21dc41c320

Simplify logic for mutable workInProgressSources (#18920)

isPrimaryRenderer is always constant for a given React build, so these two arrays do nothing.

Sophie Alpert committed May 14, 2020 at 14:30 UTC 21dc41c3205b4f721ba97d2e54f1d3b5c38cb79a
2 files changed +16 -36
packages/react-reconciler/src/ReactMutableSource.new.js
+8 -18
@@ -14,8 +14,7 @@ import {isPrimaryRenderer} from './ReactFiberHostConfig';
14 // Work in progress version numbers only apply to a single render,
15 // and should be reset before starting a new render.
16 // This tracks which mutable sources need to be reset after a render.
17 -const workInProgressPrimarySources: Array<MutableSource<any>> = [];
18 -const workInProgressSecondarySources: Array<MutableSource<any>> = [];
17 +const workInProgressSources: Array<MutableSource<any>> = [];
18
19 let rendererSigil;
20 if (__DEV__) {
@@ -24,27 +23,19 @@ if (__DEV__) {
23 }
24
25 export function markSourceAsDirty(mutableSource: MutableSource<any>): void {
27 - if (isPrimaryRenderer) {
28 - workInProgressPrimarySources.push(mutableSource);
29 - } else {
30 - workInProgressSecondarySources.push(mutableSource);
31 - }
26 + workInProgressSources.push(mutableSource);
27 }
28
29 export function resetWorkInProgressVersions(): void {
35 - if (isPrimaryRenderer) {
36 - for (let i = 0; i < workInProgressPrimarySources.length; i++) {
37 - const mutableSource = workInProgressPrimarySources[i];
30 + for (let i = 0; i < workInProgressSources.length; i++) {
31 + const mutableSource = workInProgressSources[i];
32 + if (isPrimaryRenderer) {
33 mutableSource._workInProgressVersionPrimary = null;
39 - }
40 - workInProgressPrimarySources.length = 0;
41 - } else {
42 - for (let i = 0; i < workInProgressSecondarySources.length; i++) {
43 - const mutableSource = workInProgressSecondarySources[i];
34 + } else {
35 mutableSource._workInProgressVersionSecondary = null;
36 }
46 - workInProgressSecondarySources.length = 0;
37 }
38 + workInProgressSources.length = 0;
39 }
40
41 export function getWorkInProgressVersion(
@@ -63,11 +54,10 @@ export function setWorkInProgressVersion(
54 ): void {
55 if (isPrimaryRenderer) {
56 mutableSource._workInProgressVersionPrimary = version;
66 - workInProgressPrimarySources.push(mutableSource);
57 } else {
58 mutableSource._workInProgressVersionSecondary = version;
69 - workInProgressSecondarySources.push(mutableSource);
59 }
60 + workInProgressSources.push(mutableSource);
61 }
62
63 export function warnAboutMultipleRenderersDEV(
packages/react-reconciler/src/ReactMutableSource.old.js
+8 -18
@@ -17,8 +17,7 @@ import {NoWork} from './ReactFiberExpirationTime.old';
17 // Work in progress version numbers only apply to a single render,
18 // and should be reset before starting a new render.
19 // This tracks which mutable sources need to be reset after a render.
20 -const workInProgressPrimarySources: Array<MutableSource<any>> = [];
21 -const workInProgressSecondarySources: Array<MutableSource<any>> = [];
20 +const workInProgressSources: Array<MutableSource<any>> = [];
21
22 let rendererSigil;
23 if (__DEV__) {
@@ -55,27 +54,19 @@ export function setPendingExpirationTime(
54 }
55
56 export function markSourceAsDirty(mutableSource: MutableSource<any>): void {
58 - if (isPrimaryRenderer) {
59 - workInProgressPrimarySources.push(mutableSource);
60 - } else {
61 - workInProgressSecondarySources.push(mutableSource);
62 - }
57 + workInProgressSources.push(mutableSource);
58 }
59
60 export function resetWorkInProgressVersions(): void {
66 - if (isPrimaryRenderer) {
67 - for (let i = 0; i < workInProgressPrimarySources.length; i++) {
68 - const mutableSource = workInProgressPrimarySources[i];
61 + for (let i = 0; i < workInProgressSources.length; i++) {
62 + const mutableSource = workInProgressSources[i];
63 + if (isPrimaryRenderer) {
64 mutableSource._workInProgressVersionPrimary = null;
70 - }
71 - workInProgressPrimarySources.length = 0;
72 - } else {
73 - for (let i = 0; i < workInProgressSecondarySources.length; i++) {
74 - const mutableSource = workInProgressSecondarySources[i];
65 + } else {
66 mutableSource._workInProgressVersionSecondary = null;
67 }
77 - workInProgressSecondarySources.length = 0;
68 }
69 + workInProgressSources.length = 0;
70 }
71
72 export function getWorkInProgressVersion(
@@ -94,11 +85,10 @@ export function setWorkInProgressVersion(
85 ): void {
86 if (isPrimaryRenderer) {
87 mutableSource._workInProgressVersionPrimary = version;
97 - workInProgressPrimarySources.push(mutableSource);
88 } else {
89 mutableSource._workInProgressVersionSecondary = version;
100 - workInProgressSecondarySources.push(mutableSource);
90 }
91 + workInProgressSources.push(mutableSource);
92 }
93
94 export function warnAboutMultipleRenderersDEV(