Apache Solr open-source search software
Add a comment about the recursion threshold of StringMSBRadixSorter.
Adrien Grandc996c78b474e
diff --git a/lucene/core/src/java/org/apache/lucene/util/InPlaceMergeSorter.java b/lucene/core/src/java/org/apache/lucene/util/InPlaceMergeSorter.javaindex dbf7d72ca13..1afba99f670 100644--- a/lucene/core/src/java/org/apache/lucene/util/InPlaceMergeSorter.java+++ b/lucene/core/src/java/org/apache/lucene/util/InPlaceMergeSorter.java@@ -33,7 +33,7 @@ public abstract class InPlaceMergeSorter extends Sorter {}void mergeSort(int from, int to) {- if (to - from < THRESHOLD) {+ if (to - from < INSERTION_SORT_THRESHOLD) {insertionSort(from, to);} else {final int mid = (from + to) >>> 1;diff --git a/lucene/core/src/java/org/apache/lucene/util/IntroSorter.java b/lucene/core/src/java/org/apache/lucene/util/IntroSorter.javaindex 498c06aa6ff..26f7e37dc9f 100644--- a/lucene/core/src/java/org/apache/lucene/util/IntroSorter.java+++ b/lucene/core/src/java/org/apache/lucene/util/IntroSorter.java@@ -38,7 +38,7 @@ public abstract class IntroSorter extends Sorter {}void quicksort(int from, int to, int maxDepth) {- if (to - from < THRESHOLD) {+ if (to - from < INSERTION_SORT_THRESHOLD) {insertionSort(from, to);return;} else if (--maxDepth < 0) {diff --git a/lucene/core/src/java/org/apache/lucene/util/Sorter.java b/lucene/core/src/java/org/apache/lucene/util/Sorter.javaindex 451d271072c..0ac954b0d3b 100644--- a/lucene/core/src/java/org/apache/lucene/util/Sorter.java+++ b/lucene/core/src/java/org/apache/lucene/util/Sorter.java@@ -23,7 +23,7 @@ import java.util.Comparator;* @lucene.internal */public abstract class Sorter {- static final int THRESHOLD = 20;+ static final int INSERTION_SORT_THRESHOLD = 20;/** Sole constructor, used for inheritance. */protected Sorter() {}diff --git a/lucene/core/src/java/org/apache/lucene/util/StringMSBRadixSorter.java b/lucene/core/src/java/org/apache/lucene/util/StringMSBRadixSorter.javaindex 0112d7aae83..84bd0749b5c 100644--- a/lucene/core/src/java/org/apache/lucene/util/StringMSBRadixSorter.java+++ b/lucene/core/src/java/org/apache/lucene/util/StringMSBRadixSorter.java@@ -21,10 +21,13 @@ import java.util.Arrays;/** Radix sorter for variable-length strings. This class sorts based on the most* significant byte first and falls back to {@link IntroSorter} when the size* of the buckets to sort becomes small. It is <b>NOT</b> stable.- * Worst-case memory usage is about {@code 2.3 KB} */+ * Worst-case memory usage is about {@code 2.3 KB}. */abstract class StringMSBRadixSorter extends Sorter {// after that many levels of recursion we fall back to introsort anyway+ // this is used as a protection against the fact that radix sort performs+ // worse when there are long common prefixes (probably because of cache+ // locality)private static final int LEVEL_THRESHOLD = 8;// size of histograms: 256 + 1 to indicate that the string is finishedprivate static final int HISTOGRAM_SIZE = 257;