Stabilize Vec<T>::shrink_to
This commit is contained in:
parent
9a27044f42
commit
4867a21225
@ -965,7 +965,6 @@ impl<T> BinaryHeap<T> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(shrink_to)]
|
||||
/// use std::collections::BinaryHeap;
|
||||
/// let mut heap: BinaryHeap<i32> = BinaryHeap::with_capacity(100);
|
||||
///
|
||||
@ -974,7 +973,7 @@ impl<T> BinaryHeap<T> {
|
||||
/// assert!(heap.capacity() >= 10);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
|
||||
#[stable(feature = "shrink_to", since = "1.55.0")]
|
||||
pub fn shrink_to(&mut self, min_capacity: usize) {
|
||||
self.data.shrink_to(min_capacity)
|
||||
}
|
||||
|
@ -766,7 +766,6 @@ impl<T> VecDeque<T> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(shrink_to)]
|
||||
/// use std::collections::VecDeque;
|
||||
///
|
||||
/// let mut buf = VecDeque::with_capacity(15);
|
||||
@ -777,7 +776,7 @@ impl<T> VecDeque<T> {
|
||||
/// buf.shrink_to(0);
|
||||
/// assert!(buf.capacity() >= 4);
|
||||
/// ```
|
||||
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
|
||||
#[stable(feature = "shrink_to", since = "1.55.0")]
|
||||
pub fn shrink_to(&mut self, min_capacity: usize) {
|
||||
let min_capacity = cmp::min(min_capacity, self.capacity());
|
||||
// We don't have to worry about an overflow as neither `self.len()` nor `self.capacity()`
|
||||
|
@ -1098,7 +1098,6 @@ impl String {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(shrink_to)]
|
||||
/// let mut s = String::from("foo");
|
||||
///
|
||||
/// s.reserve(100);
|
||||
@ -1111,7 +1110,7 @@ impl String {
|
||||
/// ```
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
#[inline]
|
||||
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
|
||||
#[stable(feature = "shrink_to", since = "1.55.0")]
|
||||
pub fn shrink_to(&mut self, min_capacity: usize) {
|
||||
self.vec.shrink_to(min_capacity)
|
||||
}
|
||||
|
@ -942,7 +942,6 @@ impl<T, A: Allocator> Vec<T, A> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(shrink_to)]
|
||||
/// let mut vec = Vec::with_capacity(10);
|
||||
/// vec.extend([1, 2, 3]);
|
||||
/// assert_eq!(vec.capacity(), 10);
|
||||
@ -952,7 +951,7 @@ impl<T, A: Allocator> Vec<T, A> {
|
||||
/// assert!(vec.capacity() >= 3);
|
||||
/// ```
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
|
||||
#[stable(feature = "shrink_to", since = "1.55.0")]
|
||||
pub fn shrink_to(&mut self, min_capacity: usize) {
|
||||
if self.capacity() > min_capacity {
|
||||
self.buf.shrink_to_fit(cmp::max(self.len, min_capacity));
|
||||
|
@ -665,7 +665,6 @@ where
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(shrink_to)]
|
||||
/// use std::collections::HashMap;
|
||||
///
|
||||
/// let mut map: HashMap<i32, i32> = HashMap::with_capacity(100);
|
||||
@ -678,7 +677,7 @@ where
|
||||
/// assert!(map.capacity() >= 2);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
|
||||
#[stable(feature = "shrink_to", since = "1.55.0")]
|
||||
pub fn shrink_to(&mut self, min_capacity: usize) {
|
||||
self.base.shrink_to(min_capacity);
|
||||
}
|
||||
|
@ -466,7 +466,6 @@ where
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(shrink_to)]
|
||||
/// use std::collections::HashSet;
|
||||
///
|
||||
/// let mut set = HashSet::with_capacity(100);
|
||||
@ -479,7 +478,7 @@ where
|
||||
/// assert!(set.capacity() >= 2);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
|
||||
#[stable(feature = "shrink_to", since = "1.55.0")]
|
||||
pub fn shrink_to(&mut self, min_capacity: usize) {
|
||||
self.base.shrink_to(min_capacity)
|
||||
}
|
||||
|
@ -319,7 +319,6 @@ impl OsString {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(shrink_to)]
|
||||
/// use std::ffi::OsString;
|
||||
///
|
||||
/// let mut s = OsString::from("foo");
|
||||
@ -333,7 +332,7 @@ impl OsString {
|
||||
/// assert!(s.capacity() >= 3);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
|
||||
#[stable(feature = "shrink_to", since = "1.55.0")]
|
||||
pub fn shrink_to(&mut self, min_capacity: usize) {
|
||||
self.inner.shrink_to(min_capacity)
|
||||
}
|
||||
|
@ -306,7 +306,6 @@
|
||||
#![feature(ready_macro)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(rustc_private)]
|
||||
#![feature(shrink_to)]
|
||||
#![feature(slice_concat_ext)]
|
||||
#![feature(slice_internals)]
|
||||
#![feature(slice_ptr_get)]
|
||||
|
@ -1398,7 +1398,7 @@ impl PathBuf {
|
||||
/// Invokes [`shrink_to`] on the underlying instance of [`OsString`].
|
||||
///
|
||||
/// [`shrink_to`]: OsString::shrink_to
|
||||
#[unstable(feature = "shrink_to", issue = "56431")]
|
||||
#[stable(feature = "shrink_to", since = "1.55.0")]
|
||||
#[inline]
|
||||
pub fn shrink_to(&mut self, min_capacity: usize) {
|
||||
self.inner.shrink_to(min_capacity)
|
||||
|
Loading…
x
Reference in New Issue
Block a user