use core::cmp::Ordering::{self, Less};
use core::mem::{self, size_of};
use core::ptr;
-use core::{u16, u32, u8};
use crate::borrow::ToOwned;
use crate::boxed::Box;
use crate::string::ToString;
use crate::vec::Vec;
+ // We shouldn't add inline attribute to this since this is used in
+ // `vec!` macro mostly and causes perf regression. See #71204 for
+ // discussion and perf results.
pub fn into_vec<T>(b: Box<[T]>) -> Vec<T> {
unsafe {
let len = b.len();
let b = Box::into_raw(b);
- let xs = Vec::from_raw_parts(b as *mut T, len, len);
- xs
+ Vec::from_raw_parts(b as *mut T, len, len)
}
}
impl<T> [T] {
/// Sorts the slice.
///
- /// This sort is stable (i.e., does not reorder equal elements) and `O(n log n)` worst-case.
+ /// 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.
/// Sorts the slice with a comparator function.
///
- /// This sort is stable (i.e., does not reorder equal elements) and `O(n log n)` worst-case.
+ /// This sort is stable (i.e., does not reorder equal elements) and `O(n * log(n))` worst-case.
///
/// The comparator function must define a total ordering for the elements in the slice. If
/// the ordering is not total, the order of the elements is unspecified. An order is a
/// Sorts the slice with a key extraction function.
///
- /// This sort is stable (i.e., does not reorder equal elements) and `O(m n log(m n))`
+ /// This sort is stable (i.e., does not reorder equal elements) and `O(m * n * log(n))`
/// worst-case, where the key function is `O(m)`.
///
/// For expensive key functions (e.g. functions that are not simple property accesses or
///
/// During sorting, the key function is called only once per element.
///
- /// This sort is stable (i.e., does not reorder equal elements) and `O(m n + n log n)`
+ /// This sort is stable (i.e., does not reorder equal elements) and `O(m * n + n * log(n))`
/// worst-case, where the key function is `O(m)`.
///
/// For simple key functions (e.g., functions that are property accesses or
///
/// ```should_panic
/// // this will panic at runtime
- /// b"0123456789abcdef".repeat(usize::max_value());
+ /// b"0123456789abcdef".repeat(usize::MAX);
/// ```
#[stable(feature = "repeat_generic_slice", since = "1.40.0")]
pub fn repeat(&self, n: usize) -> Vec<T>
fn clone_into(&self, target: &mut Vec<T>) {
// drop anything in target that will not be overwritten
target.truncate(self.len());
- let len = target.len();
-
- // reuse the contained values' allocations/resources.
- target.clone_from_slice(&self[..len]);
// target.len <= self.len due to the truncate above, so the
- // slice here is always in-bounds.
- target.extend_from_slice(&self[len..]);
+ // slices here are always in-bounds.
+ let (init, tail) = self.split_at(target.len());
+
+ // reuse the contained values' allocations/resources.
+ target.clone_from_slice(init);
+ target.extend_from_slice(tail);
}
}
/// 1. for every `i` in `1..runs.len()`: `runs[i - 1].len > runs[i].len`
/// 2. for every `i` in `2..runs.len()`: `runs[i - 2].len > runs[i - 1].len + runs[i].len`
///
-/// The invariants ensure that the total running time is `O(n log n)` worst-case.
+/// The invariants ensure that the total running time is `O(n * log(n))` worst-case.
fn merge_sort<T, F>(v: &mut [T], mut is_less: F)
where
F: FnMut(&T, &T) -> bool,