diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index a222dbc93a8..9b653fe2d75 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -1333,8 +1333,14 @@ impl> RcFromIter for Rc<[T]> { impl<'a, T: 'a + Clone> RcFromIter<&'a T, slice::Iter<'a, T>> for Rc<[T]> { fn from_iter(iter: slice::Iter<'a, T>) -> Self { - // Delegate to `impl From<&[T]> for Rc<[T]>` - // which will use `ptr::copy_nonoverlapping`. + // Delegate to `impl From<&[T]> for Rc<[T]>`. + // + // In the case that `T: Copy`, we get to use `ptr::copy_nonoverlapping` + // which is even more performant. + // + // In the fall-back case we have `T: Clone`. This is still better + // than the `TrustedLen` implementation as slices have a known length + // and so we get to avoid calling `size_hint` and avoid the branching. iter.as_slice().into() } } diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index f5110905a11..672481ca0de 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -1903,8 +1903,14 @@ impl> ArcFromIter for Arc<[T]> { impl<'a, T: 'a + Clone> ArcFromIter<&'a T, slice::Iter<'a, T>> for Arc<[T]> { fn from_iter(iter: slice::Iter<'a, T>) -> Self { - // Delegate to `impl From<&[T]> for Arc<[T]>` - // which will use `ptr::copy_nonoverlapping`. + // Delegate to `impl From<&[T]> for Rc<[T]>`. + // + // In the case that `T: Copy`, we get to use `ptr::copy_nonoverlapping` + // which is even more performant. + // + // In the fall-back case we have `T: Clone`. This is still better + // than the `TrustedLen` implementation as slices have a known length + // and so we get to avoid calling `size_hint` and avoid the branching. iter.as_slice().into() } }