From 3777b86f9b79306d16982ed693a5e4634be13a0e Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Thu, 31 Jan 2019 12:47:31 -0800 Subject: Stabilize slice_sort_by_cached_key --- src/liballoc/benches/lib.rs | 1 - src/liballoc/slice.rs | 3 +-- src/liballoc/tests/lib.rs | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/benches/lib.rs b/src/liballoc/benches/lib.rs index 08c69ee6e85..a1884b7d548 100644 --- a/src/liballoc/benches/lib.rs +++ b/src/liballoc/benches/lib.rs @@ -1,5 +1,4 @@ #![feature(repr_simd)] -#![feature(slice_sort_by_cached_key)] #![feature(test)] extern crate rand; diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index c4f4a80a017..1f68efd019b 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -312,7 +312,6 @@ impl [T] { /// # Examples /// /// ``` - /// #![feature(slice_sort_by_cached_key)] /// let mut v = [-5i32, 4, 32, -3, 2]; /// /// v.sort_by_cached_key(|k| k.to_string()); @@ -320,7 +319,7 @@ impl [T] { /// ``` /// /// [pdqsort]: https://github.com/orlp/pdqsort - #[unstable(feature = "slice_sort_by_cached_key", issue = "34447")] + #[stable(feature = "slice_sort_by_cached_key", since = "1.34.0")] #[inline] pub fn sort_by_cached_key(&mut self, f: F) where F: FnMut(&T) -> K, K: Ord diff --git a/src/liballoc/tests/lib.rs b/src/liballoc/tests/lib.rs index 2b63ac5c7d2..2361a7db1f7 100644 --- a/src/liballoc/tests/lib.rs +++ b/src/liballoc/tests/lib.rs @@ -4,7 +4,6 @@ #![feature(exact_size_is_empty)] #![feature(pattern)] #![feature(repeat_generic_slice)] -#![feature(slice_sort_by_cached_key)] #![feature(try_reserve)] #![feature(unboxed_closures)] #![feature(vecdeque_rotate)] -- cgit 1.4.1-3-g733a5 From 317f15304e6091a1f3cc58c52d36df037ef50db0 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 2 Feb 2019 01:32:56 -0800 Subject: Revert "Remove mentions of unstable sort_by_cached key from stable documentation" This reverts commit 9c7b69e17909ceb090a1c4b8882a4e0924a2a755. --- src/liballoc/slice.rs | 4 ++++ src/libcore/slice/mod.rs | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'src/liballoc') diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index 1f68efd019b..f4b2d463778 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -257,6 +257,10 @@ impl [T] { /// This sort is stable (i.e., does not reorder equal elements) and `O(m n log(m n))` /// worst-case, where the key function is `O(m)`. /// + /// For expensive key functions (e.g. functions that are not simple property accesses or + /// basic operations), [`sort_by_cached_key`](#method.sort_by_cached_key) is likely to be + /// significantly faster, as it does not recompute element keys. + /// /// 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). diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index acca9748372..a628fd0cfa4 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -1563,6 +1563,10 @@ impl [T] { /// randomization to avoid degenerate cases, but with a fixed seed to always provide /// deterministic behavior. /// + /// Due to its key calling strategy, [`sort_unstable_by_key`](#method.sort_unstable_by_key) + /// is likely to be slower than [`sort_by_cached_key`](#method.sort_by_cached_key) in + /// cases where the key function is expensive. + /// /// # Examples /// /// ``` -- cgit 1.4.1-3-g733a5