Index: lucene/src/java/org/apache/lucene/util/ArrayUtil.java =================================================================== --- lucene/src/java/org/apache/lucene/util/ArrayUtil.java (revision 1085007) +++ lucene/src/java/org/apache/lucene/util/ArrayUtil.java (working copy) @@ -563,6 +563,7 @@ * @param toIndex end index (exclusive) */ public static void quickSort(T[] a, int fromIndex, int toIndex, Comparator comp) { + if (toIndex-fromIndex <= 1) return; getSorter(a, comp).quickSort(fromIndex, toIndex-1); } @@ -571,6 +572,7 @@ * algorithm, but falls back to insertion sort for small arrays. */ public static void quickSort(T[] a, Comparator comp) { + if (a.length <= 1) return; quickSort(a, 0, a.length, comp); } @@ -581,6 +583,7 @@ * @param toIndex end index (exclusive) */ public static > void quickSort(T[] a, int fromIndex, int toIndex) { + if (toIndex-fromIndex <= 1) return; getSorter(a).quickSort(fromIndex, toIndex-1); } @@ -589,6 +592,7 @@ * algorithm, but falls back to insertion sort for small arrays. */ public static > void quickSort(T[] a) { + if (a.length <= 1) return; quickSort(a, 0, a.length); } @@ -601,6 +605,7 @@ * @param toIndex end index (exclusive) */ public static void mergeSort(T[] a, int fromIndex, int toIndex, Comparator comp) { + if (toIndex-fromIndex <= 1) return; getSorter(a, comp).mergeSort(fromIndex, toIndex-1); } @@ -609,6 +614,7 @@ * algorithm, but falls back to insertion sort for small arrays. */ public static void mergeSort(T[] a, Comparator comp) { + if (a.length <= 1) return; mergeSort(a, 0, a.length, comp); } @@ -619,6 +625,7 @@ * @param toIndex end index (exclusive) */ public static > void mergeSort(T[] a, int fromIndex, int toIndex) { + if (toIndex-fromIndex <= 1) return; getSorter(a).mergeSort(fromIndex, toIndex-1); } @@ -627,6 +634,7 @@ * algorithm, but falls back to insertion sort for small arrays. */ public static > void mergeSort(T[] a) { + if (a.length <= 1) return; mergeSort(a, 0, a.length); } @@ -639,6 +647,7 @@ * @param toIndex end index (exclusive) */ public static void insertionSort(T[] a, int fromIndex, int toIndex, Comparator comp) { + if (toIndex-fromIndex <= 1) return; getSorter(a, comp).insertionSort(fromIndex, toIndex-1); } @@ -647,6 +656,7 @@ * algorithm. It is only recommended to use this algorithm for partially sorted small arrays! */ public static void insertionSort(T[] a, Comparator comp) { + if (a.length <= 1) return; insertionSort(a, 0, a.length, comp); } @@ -657,6 +667,7 @@ * @param toIndex end index (exclusive) */ public static > void insertionSort(T[] a, int fromIndex, int toIndex) { + if (toIndex-fromIndex <= 1) return; getSorter(a).insertionSort(fromIndex, toIndex-1); } @@ -665,6 +676,7 @@ * algorithm. It is only recommended to use this algorithm for partially sorted small arrays! */ public static > void insertionSort(T[] a) { + if (a.length <= 1) return; insertionSort(a, 0, a.length); } Index: lucene/src/java/org/apache/lucene/util/CollectionUtil.java =================================================================== --- lucene/src/java/org/apache/lucene/util/CollectionUtil.java (revision 1085007) +++ lucene/src/java/org/apache/lucene/util/CollectionUtil.java (working copy) @@ -100,7 +100,9 @@ * @throws IllegalArgumentException if list is e.g. a linked list without random access. */ public static void quickSort(List list, Comparator comp) { - getSorter(list, comp).quickSort(0, list.size()-1); + final int l = list.size(); + if (l <= 1) return; + getSorter(list, comp).quickSort(0, l-1); } /** @@ -110,7 +112,9 @@ * @throws IllegalArgumentException if list is e.g. a linked list without random access. */ public static > void quickSort(List list) { - getSorter(list).quickSort(0, list.size()-1); + final int l = list.size(); + if (l <= 1) return; + getSorter(list).quickSort(0, l-1); } // mergeSorts: @@ -122,7 +126,9 @@ * @throws IllegalArgumentException if list is e.g. a linked list without random access. */ public static void mergeSort(List list, Comparator comp) { - getSorter(list, comp).mergeSort(0, list.size()-1); + final int l = list.size(); + if (l <= 1) return; + getSorter(list, comp).mergeSort(0, l-1); } /** @@ -132,7 +138,9 @@ * @throws IllegalArgumentException if list is e.g. a linked list without random access. */ public static > void mergeSort(List list) { - getSorter(list).mergeSort(0, list.size()-1); + final int l = list.size(); + if (l <= 1) return; + getSorter(list).mergeSort(0, l-1); } // insertionSorts: @@ -144,7 +152,9 @@ * @throws IllegalArgumentException if list is e.g. a linked list without random access. */ public static void insertionSort(List list, Comparator comp) { - getSorter(list, comp).insertionSort(0, list.size()-1); + final int l = list.size(); + if (l <= 1) return; + getSorter(list, comp).insertionSort(0, l-1); } /** @@ -154,7 +164,9 @@ * @throws IllegalArgumentException if list is e.g. a linked list without random access. */ public static > void insertionSort(List list) { - getSorter(list).insertionSort(0, list.size()-1); + final int l = list.size(); + if (l <= 1) return; + getSorter(list).insertionSort(0, l-1); } } \ No newline at end of file