X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fliballoc%2Fvec.rs;h=2f56898f4e9b66e43823aa765140932a0e082028;hb=654c180d05fedc8a9a3c793cfc747ad542d3a4f2;hp=1265d0e56b576ceed08c1f12091a4abd8053b043;hpb=f13d09abe1d7a02007ac8591dc409c8d820b903a;p=rust.git diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 1265d0e56b5..2f56898f4e9 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -491,7 +491,7 @@ pub fn capacity(&self) -> usize { /// /// # Panics /// - /// Panics if the new capacity overflows `usize`. + /// Panics if the new capacity exceeds `isize::MAX` bytes. /// /// # Examples /// @@ -1188,7 +1188,7 @@ pub fn dedup_by(&mut self, same_bucket: F) /// /// # Panics /// - /// Panics if the number of elements in the vector overflows a `usize`. + /// Panics if the new capacity exceeds `isize::MAX` bytes. /// /// # Examples /// @@ -1274,11 +1274,10 @@ unsafe fn append_elements(&mut self, other: *const [T]) { /// Creates a draining iterator that removes the specified range in the vector /// and yields the removed items. /// - /// Note 1: The element range is removed even if the iterator is only - /// partially consumed or not consumed at all. - /// - /// Note 2: It is unspecified how many elements are removed from the vector - /// if the `Drain` value is leaked. + /// When the iterator **is** dropped, all elements in the range are removed + /// from the vector, even if the iterator was not fully consumed. If the + /// iterator **is not** dropped (with [`mem::forget`] for example), it is + /// unspecified how many elements are removed. /// /// # Panics /// @@ -1801,6 +1800,21 @@ impl SpecFromElem for T { } } +impl SpecFromElem for i8 { + #[inline] + fn from_elem(elem: i8, n: usize) -> Vec { + if elem == 0 { + return Vec { buf: RawVec::with_capacity_zeroed(n), len: n }; + } + unsafe { + let mut v = Vec::with_capacity(n); + ptr::write_bytes(v.as_mut_ptr(), elem as u8, n); + v.set_len(n); + v + } + } +} + impl SpecFromElem for u8 { #[inline] fn from_elem(elem: u8, n: usize) -> Vec { @@ -1845,7 +1859,6 @@ fn is_zero(&self) -> bool { }; } -impl_is_zero!(i8, |x| x == 0); impl_is_zero!(i16, |x| x == 0); impl_is_zero!(i32, |x| x == 0); impl_is_zero!(i64, |x| x == 0);