ImmutableRange: Avoid doing expensive TreeWalker computation twice

If A follows B, then we can assume that B does not follow A.
Calling the function recursively computes that twice,
we can instead make some simple changes to "invert" the result.

Change-Id: I709aca7cb997dd2fe3980468a8c6bde6f366fb5b
This commit is contained in:
Bartosz Dziewoński 2020-10-20 10:45:59 +02:00
parent a29cecdf73
commit 6f2ada2bb4

View file

@ -435,14 +435,9 @@ class ImmutableRange {
$tw->currentNode = $boundaryPointB[0];
$AFollowsB = $tw->nextNode();
if ( $AFollowsB ) {
switch ( $this->computePosition( $boundaryPointB, $boundaryPointA ) ) {
case 'after':
return 'before';
case 'before':
return 'after';
}
// Swap variables
[ $boundaryPointB, $boundaryPointA ] = [ $boundaryPointA, $boundaryPointB ];
}
$ancestor = $boundaryPointB[0]->parentNode;
@ -467,11 +462,11 @@ class ImmutableRange {
}
if ( CommentUtils::childIndexOf( $child ) < $boundaryPointA[1] ) {
return 'after';
return $AFollowsB ? 'before' : 'after';
}
}
return 'before';
return $AFollowsB ? 'after' : 'before';
}
}