about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-07-02 23:54:32 +0000
committerbors <bors@rust-lang.org>2017-07-02 23:54:32 +0000
commit1d2db7b9e8082f0459e000985d77fc7ad0dabade (patch)
tree1e233d61fd80946db5767e8979c4246197b92597
parent0679711398bef656699e1ff6b004ecccbdb67284 (diff)
parent66f8cddae55ae3699932b424823dc21cfa566e6b (diff)
downloadrust-1d2db7b9e8082f0459e000985d77fc7ad0dabade.tar.gz
rust-1d2db7b9e8082f0459e000985d77fc7ad0dabade.zip
Auto merge of #43010 - stjepang:stabilize-sort-unstable, r=alexcrichton
Stabilize feature sort_unstable

Closes #40585
-rw-r--r--src/doc/unstable-book/src/library-features/sort-unstable.md40
-rw-r--r--src/liballoc/benches/lib.rs1
-rw-r--r--src/liballoc/lib.rs1
-rw-r--r--src/liballoc/slice.rs27
-rw-r--r--src/libcore/slice/mod.rs6
-rw-r--r--src/libcore/slice/sort.rs4
-rw-r--r--src/libcore/tests/lib.rs1
-rw-r--r--src/librustc/lib.rs1
-rw-r--r--src/librustc_incremental/lib.rs1
-rw-r--r--src/librustc_metadata/lib.rs1
10 files changed, 20 insertions, 63 deletions
diff --git a/src/doc/unstable-book/src/library-features/sort-unstable.md b/src/doc/unstable-book/src/library-features/sort-unstable.md
deleted file mode 100644
index 9effcfc774c..00000000000
--- a/src/doc/unstable-book/src/library-features/sort-unstable.md
+++ /dev/null
@@ -1,40 +0,0 @@
-# `sort_unstable`
-
-The tracking issue for this feature is: [#40585]
-
-[#40585]: https://github.com/rust-lang/rust/issues/40585
-
-------------------------
-
-The default `sort` method on slices is stable. In other words, it guarantees
-that the original order of equal elements is preserved after sorting. The
-method has several undesirable characteristics:
-
-1. It allocates a sizable chunk of memory.
-2. If you don't need stability, it is not as performant as it could be.
-
-An alternative is the new `sort_unstable` feature, which includes these
-methods for sorting slices:
-
-1. `sort_unstable`
-2. `sort_unstable_by`
-3. `sort_unstable_by_key`
-
-Unstable sorting is generally faster and makes no allocations. The majority
-of real-world sorting needs doesn't require stability, so these methods can
-very often come in handy.
-
-Another important difference is that `sort` lives in `libstd` and
-`sort_unstable` lives in `libcore`. The reason is that the former makes
-allocations and the latter doesn't.
-
-A simple example:
-
-```rust
-#![feature(sort_unstable)]
-
-let mut v = [-5, 4, 1, -3, 2];
-
-v.sort_unstable();
-assert!(v == [-5, -3, 1, 2, 4]);
-```
diff --git a/src/liballoc/benches/lib.rs b/src/liballoc/benches/lib.rs
index 5f274eec87d..174628ccd07 100644
--- a/src/liballoc/benches/lib.rs
+++ b/src/liballoc/benches/lib.rs
@@ -14,7 +14,6 @@
 #![feature(rand)]
 #![feature(repr_simd)]
 #![feature(slice_rotate)]
-#![feature(sort_unstable)]
 #![feature(test)]
 
 extern crate rand;
diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs
index ca52943ea97..23da2913136 100644
--- a/src/liballoc/lib.rs
+++ b/src/liballoc/lib.rs
@@ -83,7 +83,6 @@
 #![cfg_attr(not(test), feature(core_float))]
 #![cfg_attr(not(test), feature(exact_size_is_empty))]
 #![cfg_attr(not(test), feature(slice_rotate))]
-#![cfg_attr(not(test), feature(sort_unstable))]
 #![cfg_attr(not(test), feature(str_checked_slicing))]
 #![cfg_attr(test, feature(rand, test))]
 #![feature(allocator)]
diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs
index fe8893904eb..f4c2b9d054b 100644
--- a/src/liballoc/slice.rs
+++ b/src/liballoc/slice.rs
@@ -1144,6 +1144,10 @@ impl<T> [T] {
     ///
     /// This sort is stable (i.e. does not reorder equal elements) and `O(n log n)` worst-case.
     ///
+    /// When applicable, unstable sorting is preferred because it is generally faster than stable
+    /// sorting and it doesn't allocate auxiliary memory.
+    /// See [`sort_unstable`](#method.sort_unstable).
+    ///
     /// # Current implementation
     ///
     /// The current algorithm is an adaptive, iterative merge sort inspired by
@@ -1174,6 +1178,10 @@ impl<T> [T] {
     ///
     /// This sort is stable (i.e. does not reorder equal elements) and `O(n log n)` worst-case.
     ///
+    /// When applicable, unstable sorting is preferred because it is generally faster than stable
+    /// sorting and it doesn't allocate auxiliary memory.
+    /// See [`sort_unstable_by`](#method.sort_unstable_by).
+    ///
     /// # Current implementation
     ///
     /// The current algorithm is an adaptive, iterative merge sort inspired by
@@ -1207,6 +1215,10 @@ impl<T> [T] {
     ///
     /// This sort is stable (i.e. does not reorder equal elements) and `O(n log n)` worst-case.
     ///
+    /// When applicable, unstable sorting is preferred because it is generally faster than stable
+    /// sorting and it doesn't allocate auxiliary memory.
+    /// See [`sort_unstable_by_key`](#method.sort_unstable_by_key).
+    ///
     /// # Current implementation
     ///
     /// The current algorithm is an adaptive, iterative merge sort inspired by
@@ -1251,8 +1263,6 @@ impl<T> [T] {
     /// # Examples
     ///
     /// ```
-    /// #![feature(sort_unstable)]
-    ///
     /// let mut v = [-5, 4, 1, -3, 2];
     ///
     /// v.sort_unstable();
@@ -1260,8 +1270,7 @@ impl<T> [T] {
     /// ```
     ///
     /// [pdqsort]: https://github.com/orlp/pdqsort
-    // FIXME #40585: Mention `sort_unstable` in the documentation for `sort`.
-    #[unstable(feature = "sort_unstable", issue = "40585")]
+    #[stable(feature = "sort_unstable", since = "1.20.0")]
     #[inline]
     pub fn sort_unstable(&mut self)
         where T: Ord
@@ -1288,8 +1297,6 @@ impl<T> [T] {
     /// # Examples
     ///
     /// ```
-    /// #![feature(sort_unstable)]
-    ///
     /// let mut v = [5, 4, 1, 3, 2];
     /// v.sort_unstable_by(|a, b| a.cmp(b));
     /// assert!(v == [1, 2, 3, 4, 5]);
@@ -1300,8 +1307,7 @@ impl<T> [T] {
     /// ```
     ///
     /// [pdqsort]: https://github.com/orlp/pdqsort
-    // FIXME #40585: Mention `sort_unstable_by` in the documentation for `sort_by`.
-    #[unstable(feature = "sort_unstable", issue = "40585")]
+    #[stable(feature = "sort_unstable", since = "1.20.0")]
     #[inline]
     pub fn sort_unstable_by<F>(&mut self, compare: F)
         where F: FnMut(&T, &T) -> Ordering
@@ -1328,8 +1334,6 @@ impl<T> [T] {
     /// # Examples
     ///
     /// ```
-    /// #![feature(sort_unstable)]
-    ///
     /// let mut v = [-5i32, 4, 1, -3, 2];
     ///
     /// v.sort_unstable_by_key(|k| k.abs());
@@ -1337,8 +1341,7 @@ impl<T> [T] {
     /// ```
     ///
     /// [pdqsort]: https://github.com/orlp/pdqsort
-    // FIXME #40585: Mention `sort_unstable_by_key` in the documentation for `sort_by_key`.
-    #[unstable(feature = "sort_unstable", issue = "40585")]
+    #[stable(feature = "sort_unstable", since = "1.20.0")]
     #[inline]
     pub fn sort_unstable_by_key<B, F>(&mut self, f: F)
         where F: FnMut(&T) -> B,
diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs
index ce5da9ec2d5..62c7e7aa1cc 100644
--- a/src/libcore/slice/mod.rs
+++ b/src/libcore/slice/mod.rs
@@ -212,15 +212,15 @@ pub trait SliceExt {
     #[stable(feature = "copy_from_slice", since = "1.9.0")]
     fn copy_from_slice(&mut self, src: &[Self::Item]) where Self::Item: Copy;
 
-    #[unstable(feature = "sort_unstable", issue = "40585")]
+    #[stable(feature = "sort_unstable", since = "1.20.0")]
     fn sort_unstable(&mut self)
         where Self::Item: Ord;
 
-    #[unstable(feature = "sort_unstable", issue = "40585")]
+    #[stable(feature = "sort_unstable", since = "1.20.0")]
     fn sort_unstable_by<F>(&mut self, compare: F)
         where F: FnMut(&Self::Item, &Self::Item) -> Ordering;
 
-    #[unstable(feature = "sort_unstable", issue = "40585")]
+    #[stable(feature = "sort_unstable", since = "1.20.0")]
     fn sort_unstable_by_key<B, F>(&mut self, f: F)
         where F: FnMut(&Self::Item) -> B,
               B: Ord;
diff --git a/src/libcore/slice/sort.rs b/src/libcore/slice/sort.rs
index 6f9f2915dfe..518d56095d6 100644
--- a/src/libcore/slice/sort.rs
+++ b/src/libcore/slice/sort.rs
@@ -351,7 +351,7 @@ fn partition_in_blocks<T, F>(v: &mut [T], pivot: &T, is_less: &mut F) -> usize
 
     if start_l < end_l {
         // The left block remains.
-        // Move it's remaining out-of-order elements to the far right.
+        // Move its remaining out-of-order elements to the far right.
         debug_assert_eq!(width(l, r), block_l);
         while start_l < end_l {
             unsafe {
@@ -363,7 +363,7 @@ fn partition_in_blocks<T, F>(v: &mut [T], pivot: &T, is_less: &mut F) -> usize
         width(v.as_mut_ptr(), r)
     } else if start_r < end_r {
         // The right block remains.
-        // Move it's remaining out-of-order elements to the far left.
+        // Move its remaining out-of-order elements to the far left.
         debug_assert_eq!(width(l, r), block_r);
         while start_r < end_r {
             unsafe {
diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs
index 337f8aa31dc..b0a57d97d5e 100644
--- a/src/libcore/tests/lib.rs
+++ b/src/libcore/tests/lib.rs
@@ -34,7 +34,6 @@
 #![feature(slice_patterns)]
 #![feature(slice_rotate)]
 #![feature(sort_internals)]
-#![feature(sort_unstable)]
 #![feature(specialization)]
 #![feature(step_by)]
 #![feature(step_trait)]
diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs
index b81c56e5ee8..e4cf893375c 100644
--- a/src/librustc/lib.rs
+++ b/src/librustc/lib.rs
@@ -39,7 +39,6 @@
 #![feature(specialization)]
 #![feature(unboxed_closures)]
 #![feature(discriminant_value)]
-#![feature(sort_unstable)]
 #![feature(trace_macros)]
 #![feature(test)]
 
diff --git a/src/librustc_incremental/lib.rs b/src/librustc_incremental/lib.rs
index 5bd7a24bdaf..ac3149b90b8 100644
--- a/src/librustc_incremental/lib.rs
+++ b/src/librustc_incremental/lib.rs
@@ -20,7 +20,6 @@
 
 #![feature(rand)]
 #![feature(conservative_impl_trait)]
-#![feature(sort_unstable)]
 
 extern crate graphviz;
 #[macro_use] extern crate rustc;
diff --git a/src/librustc_metadata/lib.rs b/src/librustc_metadata/lib.rs
index 12997f24c74..99b718ea07b 100644
--- a/src/librustc_metadata/lib.rs
+++ b/src/librustc_metadata/lib.rs
@@ -26,7 +26,6 @@
 #![feature(specialization)]
 #![feature(discriminant_value)]
 #![feature(rustc_private)]
-#![feature(sort_unstable)]
 
 #[macro_use]
 extern crate log;