mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-09-24 02:48:18 +00:00
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:
parent
a29cecdf73
commit
6f2ada2bb4
|
@ -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';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue