From 997feacddd8f6e98003428265c665f7149c49a48 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Wed, 6 Nov 2019 08:09:55 -0500 Subject: Snap cfgs --- src/libcore/array/mod.rs | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/libcore/array') diff --git a/src/libcore/array/mod.rs b/src/libcore/array/mod.rs index 74a7d062d3f..901c1ee33cd 100644 --- a/src/libcore/array/mod.rs +++ b/src/libcore/array/mod.rs @@ -14,10 +14,8 @@ use crate::hash::{Hash, self}; use crate::marker::Unsize; use crate::slice::{Iter, IterMut}; -#[cfg(not(bootstrap))] mod iter; -#[cfg(not(bootstrap))] #[unstable(feature = "array_value_iter", issue = "65798")] pub use iter::IntoIter; -- cgit 1.4.1-3-g733a5 From 74b571402f980f70a4d87ec3c778af568e4fa329 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 25 Oct 2019 18:11:20 +0200 Subject: Use `drop_in_place` in `array::IntoIter::drop` This skips the loop when the element type is known not to have drop glue, even in debug mode. --- src/libcore/array/iter.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/libcore/array') diff --git a/src/libcore/array/iter.rs b/src/libcore/array/iter.rs index 307e9b90ee2..aab9463e3aa 100644 --- a/src/libcore/array/iter.rs +++ b/src/libcore/array/iter.rs @@ -92,6 +92,18 @@ where mem::transmute::<&[MaybeUninit], &[T]>(slice) } } + + /// Returns a mutable slice of all elements that have not been yielded yet. + fn as_mut_slice(&mut self) -> &mut [T] { + // This transmute is safe, same as in `as_slice` above. + let slice = &mut self.data[self.alive.clone()]; + // SAFETY: This transmute is safe. As mentioned in `new`, `MaybeUninit` retains + // the size and alignment of `T`. Furthermore, we know that all + // elements within `alive` are properly initialized. + unsafe { + mem::transmute::<&mut [MaybeUninit], &mut [T]>(slice) + } + } } @@ -184,10 +196,12 @@ where [T; N]: LengthAtMost32, { fn drop(&mut self) { - // We simply drop each element via `for_each`. This should not incur - // any significant runtime overhead and avoids adding another `unsafe` - // block. - self.by_ref().for_each(drop); + // SAFETY: This is safe: `as_mut_slice` returns exactly the sub-slice + // of elements that have not been moved out yet and that remain + // to be dropped. + unsafe { + ptr::drop_in_place(self.as_mut_slice()) + } } } -- cgit 1.4.1-3-g733a5 From 9dc3f4b05bbdacedecdfbe4116b309d5757280e1 Mon Sep 17 00:00:00 2001 From: Mark Lodato Date: Tue, 26 Nov 2019 20:58:38 -0500 Subject: Fixes small typo in array docs r? @steveklabnik --- src/libcore/array/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcore/array') diff --git a/src/libcore/array/mod.rs b/src/libcore/array/mod.rs index 901c1ee33cd..f9584a8c078 100644 --- a/src/libcore/array/mod.rs +++ b/src/libcore/array/mod.rs @@ -1,5 +1,5 @@ //! Implementations of things like `Eq` for fixed-length arrays -//! up to a certain length. Eventually we should able to generalize +//! up to a certain length. Eventually we should be able to generalize //! to all lengths. //! //! *[See also the array primitive type](../../std/primitive.array.html).* -- cgit 1.4.1-3-g733a5 From ce9b6972c25c1499c17821d2b4a51238e79f0355 Mon Sep 17 00:00:00 2001 From: Dylan DPC Date: Wed, 27 Nov 2019 10:27:30 +0100 Subject: Update mod.rs --- src/libcore/array/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcore/array') diff --git a/src/libcore/array/mod.rs b/src/libcore/array/mod.rs index f9584a8c078..38d248d701d 100644 --- a/src/libcore/array/mod.rs +++ b/src/libcore/array/mod.rs @@ -1,5 +1,5 @@ //! Implementations of things like `Eq` for fixed-length arrays -//! up to a certain length. Eventually we should be able to generalize +//! up to a certain length. Eventually, we should be able to generalize //! to all lengths. //! //! *[See also the array primitive type](../../std/primitive.array.html).* -- cgit 1.4.1-3-g733a5