Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Turn while conditions into breaks without changing the logic
This will be easier to follow when we add more code there.
  • Loading branch information
gaearon committed Oct 9, 2017
commit 28b04738c62a72d9378f45cbefc4e48bb72a1be5
16 changes: 14 additions & 2 deletions src/renderers/shared/shared/ReactTreeTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,24 @@ function traverseTwoPhase(inst, fn, arg) {
function traverseEnterLeave(from, to, fn, argFrom, argTo) {
var common = from && to ? getLowestCommonAncestor(from, to) : null;
var pathFrom = [];
while (from && from !== common) {
while (true) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to avoid while (true) since (at least in older versions) it has been known to deopt.

I appreciate the rewrite for the temp variable and easy of read. But arguably this just make the condition seem a lot more complicated than it really is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't it deopt when you have continues rather than break? I don't remember. @trueadm

if (!from) {
break;
}
if (from === common) {
break;
}
pathFrom.push(from);
from = getParent(from);
}
var pathTo = [];
while (to && to !== common) {
while (true) {
if (!to) {
break;
}
if (to === common) {
break;
}
pathTo.push(to);
to = getParent(to);
}
Expand Down