Skip to content

Commit 29e1b1f

Browse files
committed
Automated changes to remove no-op comparisons
Ran these, then prettier, then these again, then prettier again. ``` codemod --accept-all -d packages -m '\(\s*([a-zA-Z.]+) === NoWork\s*\|\|\s*\1 (<=?) ([a-zA-Z.]+)\s*\)' '(\1 \2 \3)' codemod --accept-all -d packages -m '\(\s*([a-zA-Z.]+) === NoWork\s*\|\|\s*([a-zA-Z.]+) (>=?) \1\s*\)' '(\2 \3 \1)' codemod --accept-all -d packages -m '(?<![.\w])([a-zA-Z.]+) !== NoWork\s*&&\s*\1 (>) ([a-zA-Z.]+)' '\1 \2 \3' codemod --accept-all -d packages -m '(?<![.\w])([a-zA-Z.]+) !== NoWork\s*&&\s*([a-zA-Z.]+) (<) \1' '\2 \3 \1' codemod --accept-all -d packages -m '(?<![.\w])([a-zA-Z.]+) === NoWork\s*\|\|\s*\1 (<=?) ([a-zA-Z.]+)\s*\?\s' '\1 \2 \3 ? ' codemod --accept-all -d packages -m '(?<![.\w])([a-zA-Z.]+) === NoWork\s*\|\|\s*([a-zA-Z.]+) (>=?) \1\s*\?\s' '\2 \3 \1 ? ' ```
1 parent c409c43 commit 29e1b1f

6 files changed

+31
-116
lines changed

packages/react-reconciler/src/ReactFiberBeginWork.js

+4-15
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,7 @@ function updateMemoComponent(
265265
return child;
266266
}
267267
let currentChild = ((current.child: any): Fiber); // This is always exactly one child
268-
if (
269-
updateExpirationTime === NoWork ||
270-
updateExpirationTime < renderExpirationTime
271-
) {
268+
if (updateExpirationTime < renderExpirationTime) {
272269
// This will be the props with resolved defaultProps,
273270
// unlike current.memoizedProps which will be the unresolved ones.
274271
const prevProps = currentChild.memoizedProps;
@@ -302,11 +299,7 @@ function updateSimpleMemoComponent(
302299
updateExpirationTime,
303300
renderExpirationTime: ExpirationTime,
304301
): null | Fiber {
305-
if (
306-
current !== null &&
307-
(updateExpirationTime === NoWork ||
308-
updateExpirationTime < renderExpirationTime)
309-
) {
302+
if (current !== null && updateExpirationTime < renderExpirationTime) {
310303
const prevProps = current.memoizedProps;
311304
if (
312305
shallowEqual(prevProps, nextProps) &&
@@ -1471,10 +1464,7 @@ function bailoutOnAlreadyFinishedWork(
14711464

14721465
// Check if the children have any pending work.
14731466
const childExpirationTime = workInProgress.childExpirationTime;
1474-
if (
1475-
childExpirationTime === NoWork ||
1476-
childExpirationTime < renderExpirationTime
1477-
) {
1467+
if (childExpirationTime < renderExpirationTime) {
14781468
// The children don't have any work either. We can skip them.
14791469
// TODO: Once we add back resuming, we should check if the children are
14801470
// a work-in-progress set. If so, we need to transfer their effects.
@@ -1500,8 +1490,7 @@ function beginWork(
15001490
if (
15011491
oldProps === newProps &&
15021492
!hasLegacyContextChanged() &&
1503-
(updateExpirationTime === NoWork ||
1504-
updateExpirationTime < renderExpirationTime)
1493+
updateExpirationTime < renderExpirationTime
15051494
) {
15061495
// This fiber does not have any pending work. Bailout without entering
15071496
// the begin phase. There's still some bookkeeping we that needs to be done

packages/react-reconciler/src/ReactFiberHooks.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,7 @@ export function useReducer<S, A>(
414414
newBaseState = newState;
415415
}
416416
// Update the remaining priority in the queue.
417-
if (
418-
remainingExpirationTime === NoWork ||
419-
updateExpirationTime > remainingExpirationTime
420-
) {
417+
if (updateExpirationTime > remainingExpirationTime) {
421418
remainingExpirationTime = updateExpirationTime;
422419
}
423420
} else {

packages/react-reconciler/src/ReactFiberNewContext.js

+5-15
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import warningWithoutStack from 'shared/warningWithoutStack';
2222
import {isPrimaryRenderer} from './ReactFiberHostConfig';
2323
import {createCursor, push, pop} from './ReactFiberStack';
2424
import MAX_SIGNED_31_BIT_INT from './maxSigned31BitInt';
25-
import {NoWork} from './ReactFiberExpirationTime';
2625
import {ContextProvider, ClassComponent} from 'shared/ReactWorkTags';
2726

2827
import invariant from 'shared/invariant';
@@ -169,17 +168,13 @@ export function propagateContextChange(
169168
enqueueUpdate(fiber, update);
170169
}
171170

172-
if (
173-
fiber.expirationTime === NoWork ||
174-
fiber.expirationTime < renderExpirationTime
175-
) {
171+
if (fiber.expirationTime < renderExpirationTime) {
176172
fiber.expirationTime = renderExpirationTime;
177173
}
178174
let alternate = fiber.alternate;
179175
if (
180176
alternate !== null &&
181-
(alternate.expirationTime === NoWork ||
182-
alternate.expirationTime < renderExpirationTime)
177+
alternate.expirationTime < renderExpirationTime
183178
) {
184179
alternate.expirationTime = renderExpirationTime;
185180
}
@@ -188,22 +183,17 @@ export function propagateContextChange(
188183
let node = fiber.return;
189184
while (node !== null) {
190185
alternate = node.alternate;
191-
if (
192-
node.childExpirationTime === NoWork ||
193-
node.childExpirationTime < renderExpirationTime
194-
) {
186+
if (node.childExpirationTime < renderExpirationTime) {
195187
node.childExpirationTime = renderExpirationTime;
196188
if (
197189
alternate !== null &&
198-
(alternate.childExpirationTime === NoWork ||
199-
alternate.childExpirationTime < renderExpirationTime)
190+
alternate.childExpirationTime < renderExpirationTime
200191
) {
201192
alternate.childExpirationTime = renderExpirationTime;
202193
}
203194
} else if (
204195
alternate !== null &&
205-
(alternate.childExpirationTime === NoWork ||
206-
alternate.childExpirationTime < renderExpirationTime)
196+
alternate.childExpirationTime < renderExpirationTime
207197
) {
208198
alternate.childExpirationTime = renderExpirationTime;
209199
} else {

packages/react-reconciler/src/ReactFiberPendingPriority.js

+3-15
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,10 @@ export function findEarliestOutstandingPriorityLevel(
225225

226226
const earliestPendingTime = root.earliestPendingTime;
227227
const earliestSuspendedTime = root.earliestSuspendedTime;
228-
if (
229-
earliestExpirationTime === NoWork ||
230-
(earliestPendingTime !== NoWork &&
231-
earliestPendingTime > earliestExpirationTime)
232-
) {
228+
if (earliestPendingTime > earliestExpirationTime) {
233229
earliestExpirationTime = earliestPendingTime;
234230
}
235-
if (
236-
earliestExpirationTime === NoWork ||
237-
(earliestSuspendedTime !== NoWork &&
238-
earliestSuspendedTime > earliestExpirationTime)
239-
) {
231+
if (earliestSuspendedTime > earliestExpirationTime) {
240232
earliestExpirationTime = earliestSuspendedTime;
241233
}
242234
return earliestExpirationTime;
@@ -278,11 +270,7 @@ function findNextExpirationTimeToWorkOn(completedExpirationTime, root) {
278270
}
279271

280272
let expirationTime = nextExpirationTimeToWorkOn;
281-
if (
282-
expirationTime !== NoWork &&
283-
earliestSuspendedTime !== NoWork &&
284-
earliestSuspendedTime > expirationTime
285-
) {
273+
if (expirationTime !== NoWork && earliestSuspendedTime > expirationTime) {
286274
// Expire using the earliest known expiration time.
287275
expirationTime = earliestSuspendedTime;
288276
}

packages/react-reconciler/src/ReactFiberScheduler.js

+16-59
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,7 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
605605
const updateExpirationTimeBeforeCommit = finishedWork.expirationTime;
606606
const childExpirationTimeBeforeCommit = finishedWork.childExpirationTime;
607607
const earliestRemainingTimeBeforeCommit =
608-
updateExpirationTimeBeforeCommit === NoWork ||
609-
(childExpirationTimeBeforeCommit !== NoWork &&
610-
childExpirationTimeBeforeCommit > updateExpirationTimeBeforeCommit)
608+
childExpirationTimeBeforeCommit > updateExpirationTimeBeforeCommit
611609
? childExpirationTimeBeforeCommit
612610
: updateExpirationTimeBeforeCommit;
613611
markCommittedPriorityLevels(root, earliestRemainingTimeBeforeCommit);
@@ -798,9 +796,7 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
798796
const updateExpirationTimeAfterCommit = finishedWork.expirationTime;
799797
const childExpirationTimeAfterCommit = finishedWork.childExpirationTime;
800798
const earliestRemainingTimeAfterCommit =
801-
updateExpirationTimeAfterCommit === NoWork ||
802-
(childExpirationTimeAfterCommit !== NoWork &&
803-
childExpirationTimeAfterCommit > updateExpirationTimeAfterCommit)
799+
childExpirationTimeAfterCommit > updateExpirationTimeAfterCommit
804800
? childExpirationTimeAfterCommit
805801
: updateExpirationTimeAfterCommit;
806802
if (earliestRemainingTimeAfterCommit === NoWork) {
@@ -841,10 +837,7 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
841837
// Only decrement the pending interaction count if we're done.
842838
// If there's still work at the current priority,
843839
// That indicates that we are waiting for suspense data.
844-
if (
845-
earliestRemainingTimeAfterCommit === NoWork ||
846-
scheduledExpirationTime > earliestRemainingTimeAfterCommit
847-
) {
840+
if (scheduledExpirationTime > earliestRemainingTimeAfterCommit) {
848841
pendingInteractionMap.delete(scheduledExpirationTime);
849842

850843
scheduledInteractions.forEach(interaction => {
@@ -904,18 +897,10 @@ function resetChildExpirationTime(
904897
while (child !== null) {
905898
const childUpdateExpirationTime = child.expirationTime;
906899
const childChildExpirationTime = child.childExpirationTime;
907-
if (
908-
newChildExpirationTime === NoWork ||
909-
(childUpdateExpirationTime !== NoWork &&
910-
childUpdateExpirationTime > newChildExpirationTime)
911-
) {
900+
if (childUpdateExpirationTime > newChildExpirationTime) {
912901
newChildExpirationTime = childUpdateExpirationTime;
913902
}
914-
if (
915-
newChildExpirationTime === NoWork ||
916-
(childChildExpirationTime !== NoWork &&
917-
childChildExpirationTime > newChildExpirationTime)
918-
) {
903+
if (childChildExpirationTime > newChildExpirationTime) {
919904
newChildExpirationTime = childChildExpirationTime;
920905
}
921906
if (shouldBubbleActualDurations) {
@@ -931,18 +916,10 @@ function resetChildExpirationTime(
931916
while (child !== null) {
932917
const childUpdateExpirationTime = child.expirationTime;
933918
const childChildExpirationTime = child.childExpirationTime;
934-
if (
935-
newChildExpirationTime === NoWork ||
936-
(childUpdateExpirationTime !== NoWork &&
937-
childUpdateExpirationTime > newChildExpirationTime)
938-
) {
919+
if (childUpdateExpirationTime > newChildExpirationTime) {
939920
newChildExpirationTime = childUpdateExpirationTime;
940921
}
941-
if (
942-
newChildExpirationTime === NoWork ||
943-
(childChildExpirationTime !== NoWork &&
944-
childChildExpirationTime > newChildExpirationTime)
945-
) {
922+
if (childChildExpirationTime > newChildExpirationTime) {
946923
newChildExpirationTime = childChildExpirationTime;
947924
}
948925
child = child.sibling;
@@ -1697,18 +1674,11 @@ function scheduleWorkToRoot(fiber: Fiber, expirationTime): FiberRoot | null {
16971674
}
16981675

16991676
// Update the source fiber's expiration time
1700-
if (
1701-
fiber.expirationTime === NoWork ||
1702-
fiber.expirationTime < expirationTime
1703-
) {
1677+
if (fiber.expirationTime < expirationTime) {
17041678
fiber.expirationTime = expirationTime;
17051679
}
17061680
let alternate = fiber.alternate;
1707-
if (
1708-
alternate !== null &&
1709-
(alternate.expirationTime === NoWork ||
1710-
alternate.expirationTime < expirationTime)
1711-
) {
1681+
if (alternate !== null && alternate.expirationTime < expirationTime) {
17121682
alternate.expirationTime = expirationTime;
17131683
}
17141684
// Walk the parent path to the root and update the child expiration time.
@@ -1719,22 +1689,17 @@ function scheduleWorkToRoot(fiber: Fiber, expirationTime): FiberRoot | null {
17191689
} else {
17201690
while (node !== null) {
17211691
alternate = node.alternate;
1722-
if (
1723-
node.childExpirationTime === NoWork ||
1724-
node.childExpirationTime < expirationTime
1725-
) {
1692+
if (node.childExpirationTime < expirationTime) {
17261693
node.childExpirationTime = expirationTime;
17271694
if (
17281695
alternate !== null &&
1729-
(alternate.childExpirationTime === NoWork ||
1730-
alternate.childExpirationTime < expirationTime)
1696+
alternate.childExpirationTime < expirationTime
17311697
) {
17321698
alternate.childExpirationTime = expirationTime;
17331699
}
17341700
} else if (
17351701
alternate !== null &&
1736-
(alternate.childExpirationTime === NoWork ||
1737-
alternate.childExpirationTime < expirationTime)
1702+
alternate.childExpirationTime < expirationTime
17381703
) {
17391704
alternate.childExpirationTime = expirationTime;
17401705
}
@@ -2086,10 +2051,7 @@ function addRootToSchedule(root: FiberRoot, expirationTime: ExpirationTime) {
20862051
} else {
20872052
// This root is already scheduled, but its priority may have increased.
20882053
const remainingExpirationTime = root.expirationTime;
2089-
if (
2090-
remainingExpirationTime === NoWork ||
2091-
expirationTime > remainingExpirationTime
2092-
) {
2054+
if (expirationTime > remainingExpirationTime) {
20932055
// Update the priority.
20942056
root.expirationTime = expirationTime;
20952057
}
@@ -2138,10 +2100,7 @@ function findHighestPriorityRoot() {
21382100
}
21392101
root = previousScheduledRoot.nextScheduledRoot;
21402102
} else {
2141-
if (
2142-
highestPriorityWork === NoWork ||
2143-
remainingExpirationTime > highestPriorityWork
2144-
) {
2103+
if (remainingExpirationTime > highestPriorityWork) {
21452104
// Update the priority, if it's higher
21462105
highestPriorityWork = remainingExpirationTime;
21472106
highestPriorityRoot = root;
@@ -2225,8 +2184,7 @@ function performWork(minExpirationTime: ExpirationTime, isYieldy: boolean) {
22252184
while (
22262185
nextFlushedRoot !== null &&
22272186
nextFlushedExpirationTime !== NoWork &&
2228-
(minExpirationTime === NoWork ||
2229-
minExpirationTime <= nextFlushedExpirationTime) &&
2187+
minExpirationTime <= nextFlushedExpirationTime &&
22302188
!(didYield && currentRendererTime > nextFlushedExpirationTime)
22312189
) {
22322190
performWorkOnRoot(
@@ -2242,8 +2200,7 @@ function performWork(minExpirationTime: ExpirationTime, isYieldy: boolean) {
22422200
while (
22432201
nextFlushedRoot !== null &&
22442202
nextFlushedExpirationTime !== NoWork &&
2245-
(minExpirationTime === NoWork ||
2246-
minExpirationTime <= nextFlushedExpirationTime)
2203+
minExpirationTime <= nextFlushedExpirationTime
22472204
) {
22482205
performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, false);
22492206
findHighestPriorityRoot();

packages/react-reconciler/src/ReactUpdateQueue.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,7 @@ export function processUpdateQueue<State>(
437437
}
438438
// Since this update will remain in the list, update the remaining
439439
// expiration time.
440-
if (
441-
newExpirationTime === NoWork ||
442-
newExpirationTime < updateExpirationTime
443-
) {
440+
if (newExpirationTime < updateExpirationTime) {
444441
newExpirationTime = updateExpirationTime;
445442
}
446443
} else {
@@ -490,10 +487,7 @@ export function processUpdateQueue<State>(
490487
}
491488
// Since this update will remain in the list, update the remaining
492489
// expiration time.
493-
if (
494-
newExpirationTime === NoWork ||
495-
newExpirationTime < updateExpirationTime
496-
) {
490+
if (newExpirationTime < updateExpirationTime) {
497491
newExpirationTime = updateExpirationTime;
498492
}
499493
} else {

0 commit comments

Comments
 (0)