mirror of https://github.com/apache/lucene.git
LUCENE-4946: Sorter.rotate is a no-op when one of the two adjacent slices to rotate is empty.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1482111 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
67970fcaab
commit
c1ec7aa8df
|
@ -72,7 +72,7 @@ public abstract class Sorter {
|
|||
first_cut = upper(from, mid, second_cut);
|
||||
len11 = first_cut - from;
|
||||
}
|
||||
rotate( first_cut, mid, second_cut);
|
||||
rotate(first_cut, mid, second_cut);
|
||||
final int new_mid = first_cut + len22;
|
||||
mergeInPlace(from, first_cut, new_mid);
|
||||
mergeInPlace(new_mid, second_cut, to);
|
||||
|
@ -142,7 +142,15 @@ public abstract class Sorter {
|
|||
}
|
||||
}
|
||||
|
||||
void rotate(int lo, int mid, int hi) {
|
||||
final void rotate(int lo, int mid, int hi) {
|
||||
assert lo <= mid && mid <= hi;
|
||||
if (lo == mid || mid == hi) {
|
||||
return;
|
||||
}
|
||||
doRotate(lo, mid, hi);
|
||||
}
|
||||
|
||||
void doRotate(int lo, int mid, int hi) {
|
||||
if (mid - lo == hi - mid) {
|
||||
// happens rarely but saves n/2 swaps
|
||||
while (mid < hi) {
|
||||
|
|
|
@ -205,9 +205,9 @@ public abstract class TimSorter extends Sorter {
|
|||
}
|
||||
|
||||
@Override
|
||||
void rotate(int lo, int mid, int hi) {
|
||||
int len1 = mid - lo;
|
||||
int len2 = hi - mid;
|
||||
void doRotate(int lo, int mid, int hi) {
|
||||
final int len1 = mid - lo;
|
||||
final int len2 = hi - mid;
|
||||
if (len1 == len2) {
|
||||
while (mid < hi) {
|
||||
swap(lo++, mid++);
|
||||
|
|
Loading…
Reference in New Issue