Skip to content

Commit 5350e22

Browse files
author
Stjepan Glavina
committed
Stabilize feature sort_unstable
1 parent d41b791 commit 5350e22

File tree

3 files changed

+17
-54
lines changed

3 files changed

+17
-54
lines changed

src/doc/unstable-book/src/library-features/sort-unstable.md

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/liballoc/slice.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,10 @@ impl<T> [T] {
11441144
///
11451145
/// This sort is stable (i.e. does not reorder equal elements) and `O(n log n)` worst-case.
11461146
///
1147+
/// When applicable, unstable sorting is preferred because it is generally faster than stable
1148+
/// sorting and it doesn't allocate auxiliary memory.
1149+
/// See [`sort_unstable`](#method.sort_unstable).
1150+
///
11471151
/// # Current implementation
11481152
///
11491153
/// The current algorithm is an adaptive, iterative merge sort inspired by
@@ -1174,6 +1178,10 @@ impl<T> [T] {
11741178
///
11751179
/// This sort is stable (i.e. does not reorder equal elements) and `O(n log n)` worst-case.
11761180
///
1181+
/// When applicable, unstable sorting is preferred because it is generally faster than stable
1182+
/// sorting and it doesn't allocate auxiliary memory.
1183+
/// See [`sort_unstable_by`](#method.sort_unstable_by).
1184+
///
11771185
/// # Current implementation
11781186
///
11791187
/// The current algorithm is an adaptive, iterative merge sort inspired by
@@ -1207,6 +1215,10 @@ impl<T> [T] {
12071215
///
12081216
/// This sort is stable (i.e. does not reorder equal elements) and `O(n log n)` worst-case.
12091217
///
1218+
/// When applicable, unstable sorting is preferred because it is generally faster than stable
1219+
/// sorting and it doesn't allocate auxiliary memory.
1220+
/// See [`sort_unstable_by_key`](#method.sort_unstable_by_key).
1221+
///
12101222
/// # Current implementation
12111223
///
12121224
/// The current algorithm is an adaptive, iterative merge sort inspired by
@@ -1251,17 +1263,14 @@ impl<T> [T] {
12511263
/// # Examples
12521264
///
12531265
/// ```
1254-
/// #![feature(sort_unstable)]
1255-
///
12561266
/// let mut v = [-5, 4, 1, -3, 2];
12571267
///
12581268
/// v.sort_unstable();
12591269
/// assert!(v == [-5, -3, 1, 2, 4]);
12601270
/// ```
12611271
///
12621272
/// [pdqsort]: https://github.com/orlp/pdqsort
1263-
// FIXME #40585: Mention `sort_unstable` in the documentation for `sort`.
1264-
#[unstable(feature = "sort_unstable", issue = "40585")]
1273+
#[stable(feature = "sort_unstable", since = "1.20.0")]
12651274
#[inline]
12661275
pub fn sort_unstable(&mut self)
12671276
where T: Ord
@@ -1288,8 +1297,6 @@ impl<T> [T] {
12881297
/// # Examples
12891298
///
12901299
/// ```
1291-
/// #![feature(sort_unstable)]
1292-
///
12931300
/// let mut v = [5, 4, 1, 3, 2];
12941301
/// v.sort_unstable_by(|a, b| a.cmp(b));
12951302
/// assert!(v == [1, 2, 3, 4, 5]);
@@ -1300,8 +1307,7 @@ impl<T> [T] {
13001307
/// ```
13011308
///
13021309
/// [pdqsort]: https://github.com/orlp/pdqsort
1303-
// FIXME #40585: Mention `sort_unstable_by` in the documentation for `sort_by`.
1304-
#[unstable(feature = "sort_unstable", issue = "40585")]
1310+
#[stable(feature = "sort_unstable", since = "1.20.0")]
13051311
#[inline]
13061312
pub fn sort_unstable_by<F>(&mut self, compare: F)
13071313
where F: FnMut(&T, &T) -> Ordering
@@ -1328,17 +1334,14 @@ impl<T> [T] {
13281334
/// # Examples
13291335
///
13301336
/// ```
1331-
/// #![feature(sort_unstable)]
1332-
///
13331337
/// let mut v = [-5i32, 4, 1, -3, 2];
13341338
///
13351339
/// v.sort_unstable_by_key(|k| k.abs());
13361340
/// assert!(v == [1, 2, -3, 4, -5]);
13371341
/// ```
13381342
///
13391343
/// [pdqsort]: https://github.com/orlp/pdqsort
1340-
// FIXME #40585: Mention `sort_unstable_by_key` in the documentation for `sort_by_key`.
1341-
#[unstable(feature = "sort_unstable", issue = "40585")]
1344+
#[stable(feature = "sort_unstable", since = "1.20.0")]
13421345
#[inline]
13431346
pub fn sort_unstable_by_key<B, F>(&mut self, f: F)
13441347
where F: FnMut(&T) -> B,

src/libcore/slice/sort.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ fn partition_in_blocks<T, F>(v: &mut [T], pivot: &T, is_less: &mut F) -> usize
351351

352352
if start_l < end_l {
353353
// The left block remains.
354-
// Move it's remaining out-of-order elements to the far right.
354+
// Move its remaining out-of-order elements to the far right.
355355
debug_assert_eq!(width(l, r), block_l);
356356
while start_l < end_l {
357357
unsafe {
@@ -363,7 +363,7 @@ fn partition_in_blocks<T, F>(v: &mut [T], pivot: &T, is_less: &mut F) -> usize
363363
width(v.as_mut_ptr(), r)
364364
} else if start_r < end_r {
365365
// The right block remains.
366-
// Move it's remaining out-of-order elements to the far left.
366+
// Move its remaining out-of-order elements to the far left.
367367
debug_assert_eq!(width(l, r), block_r);
368368
while start_r < end_r {
369369
unsafe {

0 commit comments

Comments
 (0)