mirror of https://github.com/apache/lucene.git
Avoid sorting values of multi-valued writers if there is a single value. (#12039)
They currently call `Arrays#sort`, which incurs a tiny bit of overhead due to range checks and some logic to determine the optimal sorting algorithm to use depending on the number of values. We can skip this overhead in the case when there is a single value.
This commit is contained in:
parent
008a0d4206
commit
e9dc4f9188
|
@ -72,7 +72,9 @@ class SortedNumericDocValuesWriter extends DocValuesWriter<SortedNumericDocValue
|
||||||
if (currentDoc == -1) {
|
if (currentDoc == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Arrays.sort(currentValues, 0, currentUpto);
|
if (currentUpto > 1) {
|
||||||
|
Arrays.sort(currentValues, 0, currentUpto);
|
||||||
|
}
|
||||||
for (int i = 0; i < currentUpto; i++) {
|
for (int i = 0; i < currentUpto; i++) {
|
||||||
pending.add(currentValues[i]);
|
pending.add(currentValues[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,9 @@ class SortedSetDocValuesWriter extends DocValuesWriter<SortedSetDocValues> {
|
||||||
if (currentDoc == -1) {
|
if (currentDoc == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Arrays.sort(currentValues, 0, currentUpto);
|
if (currentUpto > 1) {
|
||||||
|
Arrays.sort(currentValues, 0, currentUpto);
|
||||||
|
}
|
||||||
int lastValue = -1;
|
int lastValue = -1;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (int i = 0; i < currentUpto; i++) {
|
for (int i = 0; i < currentUpto; i++) {
|
||||||
|
|
Loading…
Reference in New Issue