mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Remove unnecessary comparisons
Ran these, then prettier, then these 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 ? ' ```
This commit is contained in:
+3
-11
@@ -243,11 +243,7 @@ function updatePureComponent(
|
||||
) {
|
||||
const render = Component.render;
|
||||
|
||||
if (
|
||||
current !== null &&
|
||||
(updateExpirationTime === NoWork ||
|
||||
updateExpirationTime > renderExpirationTime)
|
||||
) {
|
||||
if (current !== null && updateExpirationTime > renderExpirationTime) {
|
||||
const prevProps = current.memoizedProps;
|
||||
// Default to shallow comparison
|
||||
let compare = Component.compare;
|
||||
@@ -1351,10 +1347,7 @@ function bailoutOnAlreadyFinishedWork(
|
||||
|
||||
// Check if the children have any pending work.
|
||||
const childExpirationTime = workInProgress.childExpirationTime;
|
||||
if (
|
||||
childExpirationTime === NoWork ||
|
||||
childExpirationTime > renderExpirationTime
|
||||
) {
|
||||
if (childExpirationTime > renderExpirationTime) {
|
||||
// The children don't have any work either. We can skip them.
|
||||
// TODO: Once we add back resuming, we should check if the children are
|
||||
// a work-in-progress set. If so, we need to transfer their effects.
|
||||
@@ -1380,8 +1373,7 @@ function beginWork(
|
||||
if (
|
||||
oldProps === newProps &&
|
||||
!hasLegacyContextChanged() &&
|
||||
(updateExpirationTime === NoWork ||
|
||||
updateExpirationTime > renderExpirationTime)
|
||||
updateExpirationTime > renderExpirationTime
|
||||
) {
|
||||
// This fiber does not have any pending work. Bailout without entering
|
||||
// the begin phase. There's still some bookkeeping we that needs to be done
|
||||
|
||||
+5
-14
@@ -177,17 +177,13 @@ export function propagateContextChange(
|
||||
enqueueUpdate(fiber, update);
|
||||
}
|
||||
|
||||
if (
|
||||
fiber.expirationTime === NoWork ||
|
||||
fiber.expirationTime > renderExpirationTime
|
||||
) {
|
||||
if (fiber.expirationTime > renderExpirationTime) {
|
||||
fiber.expirationTime = renderExpirationTime;
|
||||
}
|
||||
let alternate = fiber.alternate;
|
||||
if (
|
||||
alternate !== null &&
|
||||
(alternate.expirationTime === NoWork ||
|
||||
alternate.expirationTime > renderExpirationTime)
|
||||
alternate.expirationTime > renderExpirationTime
|
||||
) {
|
||||
alternate.expirationTime = renderExpirationTime;
|
||||
}
|
||||
@@ -196,22 +192,17 @@ export function propagateContextChange(
|
||||
let node = fiber.return;
|
||||
while (node !== null) {
|
||||
alternate = node.alternate;
|
||||
if (
|
||||
node.childExpirationTime === NoWork ||
|
||||
node.childExpirationTime > renderExpirationTime
|
||||
) {
|
||||
if (node.childExpirationTime > renderExpirationTime) {
|
||||
node.childExpirationTime = renderExpirationTime;
|
||||
if (
|
||||
alternate !== null &&
|
||||
(alternate.childExpirationTime === NoWork ||
|
||||
alternate.childExpirationTime > renderExpirationTime)
|
||||
alternate.childExpirationTime > renderExpirationTime
|
||||
) {
|
||||
alternate.childExpirationTime = renderExpirationTime;
|
||||
}
|
||||
} else if (
|
||||
alternate !== null &&
|
||||
(alternate.childExpirationTime === NoWork ||
|
||||
alternate.childExpirationTime > renderExpirationTime)
|
||||
alternate.childExpirationTime > renderExpirationTime
|
||||
) {
|
||||
alternate.childExpirationTime = renderExpirationTime;
|
||||
} else {
|
||||
|
||||
+3
-15
@@ -225,18 +225,10 @@ export function findEarliestOutstandingPriorityLevel(
|
||||
|
||||
const earliestPendingTime = root.earliestPendingTime;
|
||||
const earliestSuspendedTime = root.earliestSuspendedTime;
|
||||
if (
|
||||
earliestExpirationTime === NoWork ||
|
||||
(earliestPendingTime !== NoWork &&
|
||||
earliestPendingTime < earliestExpirationTime)
|
||||
) {
|
||||
if (earliestPendingTime < earliestExpirationTime) {
|
||||
earliestExpirationTime = earliestPendingTime;
|
||||
}
|
||||
if (
|
||||
earliestExpirationTime === NoWork ||
|
||||
(earliestSuspendedTime !== NoWork &&
|
||||
earliestSuspendedTime < earliestExpirationTime)
|
||||
) {
|
||||
if (earliestSuspendedTime < earliestExpirationTime) {
|
||||
earliestExpirationTime = earliestSuspendedTime;
|
||||
}
|
||||
return earliestExpirationTime;
|
||||
@@ -278,11 +270,7 @@ function findNextExpirationTimeToWorkOn(completedExpirationTime, root) {
|
||||
}
|
||||
|
||||
let expirationTime = nextExpirationTimeToWorkOn;
|
||||
if (
|
||||
expirationTime !== NoWork &&
|
||||
earliestSuspendedTime !== NoWork &&
|
||||
earliestSuspendedTime < expirationTime
|
||||
) {
|
||||
if (expirationTime !== NoWork && earliestSuspendedTime < expirationTime) {
|
||||
// Expire using the earliest known expiration time.
|
||||
expirationTime = earliestSuspendedTime;
|
||||
}
|
||||
|
||||
+16
-59
@@ -556,9 +556,7 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
|
||||
const updateExpirationTimeBeforeCommit = finishedWork.expirationTime;
|
||||
const childExpirationTimeBeforeCommit = finishedWork.childExpirationTime;
|
||||
const earliestRemainingTimeBeforeCommit =
|
||||
updateExpirationTimeBeforeCommit === NoWork ||
|
||||
(childExpirationTimeBeforeCommit !== NoWork &&
|
||||
childExpirationTimeBeforeCommit < updateExpirationTimeBeforeCommit)
|
||||
childExpirationTimeBeforeCommit < updateExpirationTimeBeforeCommit
|
||||
? childExpirationTimeBeforeCommit
|
||||
: updateExpirationTimeBeforeCommit;
|
||||
markCommittedPriorityLevels(root, earliestRemainingTimeBeforeCommit);
|
||||
@@ -733,9 +731,7 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
|
||||
const updateExpirationTimeAfterCommit = finishedWork.expirationTime;
|
||||
const childExpirationTimeAfterCommit = finishedWork.childExpirationTime;
|
||||
const earliestRemainingTimeAfterCommit =
|
||||
updateExpirationTimeAfterCommit === NoWork ||
|
||||
(childExpirationTimeAfterCommit !== NoWork &&
|
||||
childExpirationTimeAfterCommit < updateExpirationTimeAfterCommit)
|
||||
childExpirationTimeAfterCommit < updateExpirationTimeAfterCommit
|
||||
? childExpirationTimeAfterCommit
|
||||
: updateExpirationTimeAfterCommit;
|
||||
if (earliestRemainingTimeAfterCommit === NoWork) {
|
||||
@@ -776,10 +772,7 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
|
||||
// Only decrement the pending interaction count if we're done.
|
||||
// If there's still work at the current priority,
|
||||
// That indicates that we are waiting for suspense data.
|
||||
if (
|
||||
earliestRemainingTimeAfterCommit === NoWork ||
|
||||
scheduledExpirationTime < earliestRemainingTimeAfterCommit
|
||||
) {
|
||||
if (scheduledExpirationTime < earliestRemainingTimeAfterCommit) {
|
||||
pendingInteractionMap.delete(scheduledExpirationTime);
|
||||
|
||||
scheduledInteractions.forEach(interaction => {
|
||||
@@ -839,18 +832,10 @@ function resetChildExpirationTime(
|
||||
while (child !== null) {
|
||||
const childUpdateExpirationTime = child.expirationTime;
|
||||
const childChildExpirationTime = child.childExpirationTime;
|
||||
if (
|
||||
newChildExpirationTime === NoWork ||
|
||||
(childUpdateExpirationTime !== NoWork &&
|
||||
childUpdateExpirationTime < newChildExpirationTime)
|
||||
) {
|
||||
if (childUpdateExpirationTime < newChildExpirationTime) {
|
||||
newChildExpirationTime = childUpdateExpirationTime;
|
||||
}
|
||||
if (
|
||||
newChildExpirationTime === NoWork ||
|
||||
(childChildExpirationTime !== NoWork &&
|
||||
childChildExpirationTime < newChildExpirationTime)
|
||||
) {
|
||||
if (childChildExpirationTime < newChildExpirationTime) {
|
||||
newChildExpirationTime = childChildExpirationTime;
|
||||
}
|
||||
if (shouldBubbleActualDurations) {
|
||||
@@ -866,18 +851,10 @@ function resetChildExpirationTime(
|
||||
while (child !== null) {
|
||||
const childUpdateExpirationTime = child.expirationTime;
|
||||
const childChildExpirationTime = child.childExpirationTime;
|
||||
if (
|
||||
newChildExpirationTime === NoWork ||
|
||||
(childUpdateExpirationTime !== NoWork &&
|
||||
childUpdateExpirationTime < newChildExpirationTime)
|
||||
) {
|
||||
if (childUpdateExpirationTime < newChildExpirationTime) {
|
||||
newChildExpirationTime = childUpdateExpirationTime;
|
||||
}
|
||||
if (
|
||||
newChildExpirationTime === NoWork ||
|
||||
(childChildExpirationTime !== NoWork &&
|
||||
childChildExpirationTime < newChildExpirationTime)
|
||||
) {
|
||||
if (childChildExpirationTime < newChildExpirationTime) {
|
||||
newChildExpirationTime = childChildExpirationTime;
|
||||
}
|
||||
child = child.sibling;
|
||||
@@ -1645,18 +1622,11 @@ function scheduleWorkToRoot(fiber: Fiber, expirationTime): FiberRoot | null {
|
||||
}
|
||||
|
||||
// Update the source fiber's expiration time
|
||||
if (
|
||||
fiber.expirationTime === NoWork ||
|
||||
fiber.expirationTime > expirationTime
|
||||
) {
|
||||
if (fiber.expirationTime > expirationTime) {
|
||||
fiber.expirationTime = expirationTime;
|
||||
}
|
||||
let alternate = fiber.alternate;
|
||||
if (
|
||||
alternate !== null &&
|
||||
(alternate.expirationTime === NoWork ||
|
||||
alternate.expirationTime > expirationTime)
|
||||
) {
|
||||
if (alternate !== null && alternate.expirationTime > expirationTime) {
|
||||
alternate.expirationTime = expirationTime;
|
||||
}
|
||||
// Walk the parent path to the root and update the child expiration time.
|
||||
@@ -1667,22 +1637,17 @@ function scheduleWorkToRoot(fiber: Fiber, expirationTime): FiberRoot | null {
|
||||
} else {
|
||||
while (node !== null) {
|
||||
alternate = node.alternate;
|
||||
if (
|
||||
node.childExpirationTime === NoWork ||
|
||||
node.childExpirationTime > expirationTime
|
||||
) {
|
||||
if (node.childExpirationTime > expirationTime) {
|
||||
node.childExpirationTime = expirationTime;
|
||||
if (
|
||||
alternate !== null &&
|
||||
(alternate.childExpirationTime === NoWork ||
|
||||
alternate.childExpirationTime > expirationTime)
|
||||
alternate.childExpirationTime > expirationTime
|
||||
) {
|
||||
alternate.childExpirationTime = expirationTime;
|
||||
}
|
||||
} else if (
|
||||
alternate !== null &&
|
||||
(alternate.childExpirationTime === NoWork ||
|
||||
alternate.childExpirationTime > expirationTime)
|
||||
alternate.childExpirationTime > expirationTime
|
||||
) {
|
||||
alternate.childExpirationTime = expirationTime;
|
||||
}
|
||||
@@ -2031,10 +1996,7 @@ function addRootToSchedule(root: FiberRoot, expirationTime: ExpirationTime) {
|
||||
} else {
|
||||
// This root is already scheduled, but its priority may have increased.
|
||||
const remainingExpirationTime = root.expirationTime;
|
||||
if (
|
||||
remainingExpirationTime === NoWork ||
|
||||
expirationTime < remainingExpirationTime
|
||||
) {
|
||||
if (expirationTime < remainingExpirationTime) {
|
||||
// Update the priority.
|
||||
root.expirationTime = expirationTime;
|
||||
}
|
||||
@@ -2083,10 +2045,7 @@ function findHighestPriorityRoot() {
|
||||
}
|
||||
root = previousScheduledRoot.nextScheduledRoot;
|
||||
} else {
|
||||
if (
|
||||
highestPriorityWork === NoWork ||
|
||||
remainingExpirationTime < highestPriorityWork
|
||||
) {
|
||||
if (remainingExpirationTime < highestPriorityWork) {
|
||||
// Update the priority, if it's higher
|
||||
highestPriorityWork = remainingExpirationTime;
|
||||
highestPriorityRoot = root;
|
||||
@@ -2153,8 +2112,7 @@ function performWork(minExpirationTime: ExpirationTime, dl: Deadline | null) {
|
||||
while (
|
||||
nextFlushedRoot !== null &&
|
||||
nextFlushedExpirationTime !== NoWork &&
|
||||
(minExpirationTime === NoWork ||
|
||||
minExpirationTime >= nextFlushedExpirationTime) &&
|
||||
minExpirationTime >= nextFlushedExpirationTime &&
|
||||
(!deadlineDidExpire || currentRendererTime >= nextFlushedExpirationTime)
|
||||
) {
|
||||
performWorkOnRoot(
|
||||
@@ -2170,8 +2128,7 @@ function performWork(minExpirationTime: ExpirationTime, dl: Deadline | null) {
|
||||
while (
|
||||
nextFlushedRoot !== null &&
|
||||
nextFlushedExpirationTime !== NoWork &&
|
||||
(minExpirationTime === NoWork ||
|
||||
minExpirationTime >= nextFlushedExpirationTime)
|
||||
minExpirationTime >= nextFlushedExpirationTime
|
||||
) {
|
||||
performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, true);
|
||||
findHighestPriorityRoot();
|
||||
|
||||
+2
-8
@@ -437,10 +437,7 @@ export function processUpdateQueue<State>(
|
||||
}
|
||||
// Since this update will remain in the list, update the remaining
|
||||
// expiration time.
|
||||
if (
|
||||
newExpirationTime === NoWork ||
|
||||
newExpirationTime > updateExpirationTime
|
||||
) {
|
||||
if (newExpirationTime > updateExpirationTime) {
|
||||
newExpirationTime = updateExpirationTime;
|
||||
}
|
||||
} else {
|
||||
@@ -490,10 +487,7 @@ export function processUpdateQueue<State>(
|
||||
}
|
||||
// Since this update will remain in the list, update the remaining
|
||||
// expiration time.
|
||||
if (
|
||||
newExpirationTime === NoWork ||
|
||||
newExpirationTime > updateExpirationTime
|
||||
) {
|
||||
if (newExpirationTime > updateExpirationTime) {
|
||||
newExpirationTime = updateExpirationTime;
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user