Commit 317f153 1 parent 3777b86 commit 317f153 Copy full SHA for 317f153
File tree 2 files changed +8
-0
lines changed
2 files changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -257,6 +257,10 @@ impl<T> [T] {
257
257
/// This sort is stable (i.e., does not reorder equal elements) and `O(m n log(m n))`
258
258
/// worst-case, where the key function is `O(m)`.
259
259
///
260
+ /// For expensive key functions (e.g. functions that are not simple property accesses or
261
+ /// basic operations), [`sort_by_cached_key`](#method.sort_by_cached_key) is likely to be
262
+ /// significantly faster, as it does not recompute element keys.
263
+ ///
260
264
/// When applicable, unstable sorting is preferred because it is generally faster than stable
261
265
/// sorting and it doesn't allocate auxiliary memory.
262
266
/// See [`sort_unstable_by_key`](#method.sort_unstable_by_key).
Original file line number Diff line number Diff line change @@ -1563,6 +1563,10 @@ impl<T> [T] {
1563
1563
/// randomization to avoid degenerate cases, but with a fixed seed to always provide
1564
1564
/// deterministic behavior.
1565
1565
///
1566
+ /// Due to its key calling strategy, [`sort_unstable_by_key`](#method.sort_unstable_by_key)
1567
+ /// is likely to be slower than [`sort_by_cached_key`](#method.sort_by_cached_key) in
1568
+ /// cases where the key function is expensive.
1569
+ ///
1566
1570
/// # Examples
1567
1571
///
1568
1572
/// ```
You can’t perform that action at this time.
0 commit comments