@@ -1064,8 +1064,17 @@ impl<T> [T] {
1064
1064
1065
1065
/// This is equivalent to `self.sort_by(|a, b| a.cmp(b))`.
1066
1066
///
1067
- /// This sort is stable and `O(n log n)` worst-case, but allocates
1068
- /// temporary storage half the size of `self`.
1067
+ /// This sort is stable (i.e. does not reorder equal elements) and `O(n log n)` worst-case.
1068
+ ///
1069
+ /// # Current implementation
1070
+ ///
1071
+ /// The current algorithm is an adaptive, iterative merge sort inspired by
1072
+ /// [timsort](https://en.wikipedia.org/wiki/Timsort).
1073
+ /// It is designed to be very fast in cases where the slice is nearly sorted, or consists of
1074
+ /// two or more sorted sequences concatenated one after another.
1075
+ ///
1076
+ /// Also, it allocates temporary storage half the size of `self`, but for short slices a
1077
+ /// non-allocating insertion sort is used instead.
1069
1078
///
1070
1079
/// # Examples
1071
1080
///
@@ -1083,11 +1092,19 @@ impl<T> [T] {
1083
1092
self . sort_by ( |a, b| a. cmp ( b) )
1084
1093
}
1085
1094
1086
- /// Sorts the slice, in place, using `f` to extract a key by which to
1087
- /// order the sort by.
1095
+ /// Sorts the slice using `f` to extract a key to compare elements by.
1096
+ ///
1097
+ /// This sort is stable (i.e. does not reorder equal elements) and `O(n log n)` worst-case.
1098
+ ///
1099
+ /// # Current implementation
1088
1100
///
1089
- /// This sort is stable and `O(n log n)` worst-case, but allocates
1090
- /// temporary storage half the size of `self`.
1101
+ /// The current algorithm is an adaptive, iterative merge sort inspired by
1102
+ /// [timsort](https://en.wikipedia.org/wiki/Timsort).
1103
+ /// It is designed to be very fast in cases where the slice is nearly sorted, or consists of
1104
+ /// two or more sorted sequences concatenated one after another.
1105
+ ///
1106
+ /// Also, it allocates temporary storage half the size of `self`, but for short slices a
1107
+ /// non-allocating insertion sort is used instead.
1091
1108
///
1092
1109
/// # Examples
1093
1110
///
@@ -1105,11 +1122,19 @@ impl<T> [T] {
1105
1122
self . sort_by ( |a, b| f ( a) . cmp ( & f ( b) ) )
1106
1123
}
1107
1124
1108
- /// Sorts the slice, in place, using `compare` to compare
1109
- /// elements.
1125
+ /// Sorts the slice using `compare` to compare elements.
1126
+ ///
1127
+ /// This sort is stable (i.e. does not reorder equal elements) and `O(n log n)` worst-case.
1128
+ ///
1129
+ /// # Current implementation
1130
+ ///
1131
+ /// The current algorithm is an adaptive, iterative merge sort inspired by
1132
+ /// [timsort](https://en.wikipedia.org/wiki/Timsort).
1133
+ /// It is designed to be very fast in cases where the slice is nearly sorted, or consists of
1134
+ /// two or more sorted sequences concatenated one after another.
1110
1135
///
1111
- /// This sort is stable and `O(n log n)` worst-case , but allocates
1112
- /// temporary storage half the size of `self` .
1136
+ /// Also, it allocates temporary storage half the size of `self` , but for short slices a
1137
+ /// non-allocating insertion sort is used instead .
1113
1138
///
1114
1139
/// # Examples
1115
1140
///
@@ -1535,7 +1560,7 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F)
1535
1560
1536
1561
// FIXME #12092: These numbers are platform-specific and need more extensive testing/tuning.
1537
1562
//
1538
- // If `v` has length up to `insertion_len `, simply switch to insertion sort because it is going
1563
+ // If `v` has length up to `max_insertion `, simply switch to insertion sort because it is going
1539
1564
// to perform better than merge sort. For bigger types `T`, the threshold is smaller.
1540
1565
//
1541
1566
// Short runs are extended using insertion sort to span at least `min_run` elements, in order
0 commit comments