Skip to content

Commit 6b8417b

Browse files
committed
shared_from_iter: Clarify slice::Iter specialization impl.
1 parent 85978d0 commit 6b8417b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/liballoc/rc.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1333,8 +1333,14 @@ impl<T, I: iter::TrustedLen<Item = T>> RcFromIter<T, I> for Rc<[T]> {
13331333

13341334
impl<'a, T: 'a + Clone> RcFromIter<&'a T, slice::Iter<'a, T>> for Rc<[T]> {
13351335
fn from_iter(iter: slice::Iter<'a, T>) -> Self {
1336-
// Delegate to `impl<T: Clone> From<&[T]> for Rc<[T]>`
1337-
// which will use `ptr::copy_nonoverlapping`.
1336+
// Delegate to `impl<T: Clone> From<&[T]> for Rc<[T]>`.
1337+
//
1338+
// In the case that `T: Copy`, we get to use `ptr::copy_nonoverlapping`
1339+
// which is even more performant.
1340+
//
1341+
// In the fall-back case we have `T: Clone`. This is still better
1342+
// than the `TrustedLen` implementation as slices have a known length
1343+
// and so we get to avoid calling `size_hint` and avoid the branching.
13381344
iter.as_slice().into()
13391345
}
13401346
}

src/liballoc/sync.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1903,8 +1903,14 @@ impl<T, I: iter::TrustedLen<Item = T>> ArcFromIter<T, I> for Arc<[T]> {
19031903

19041904
impl<'a, T: 'a + Clone> ArcFromIter<&'a T, slice::Iter<'a, T>> for Arc<[T]> {
19051905
fn from_iter(iter: slice::Iter<'a, T>) -> Self {
1906-
// Delegate to `impl<T: Clone> From<&[T]> for Arc<[T]>`
1907-
// which will use `ptr::copy_nonoverlapping`.
1906+
// Delegate to `impl<T: Clone> From<&[T]> for Rc<[T]>`.
1907+
//
1908+
// In the case that `T: Copy`, we get to use `ptr::copy_nonoverlapping`
1909+
// which is even more performant.
1910+
//
1911+
// In the fall-back case we have `T: Clone`. This is still better
1912+
// than the `TrustedLen` implementation as slices have a known length
1913+
// and so we get to avoid calling `size_hint` and avoid the branching.
19081914
iter.as_slice().into()
19091915
}
19101916
}

0 commit comments

Comments
 (0)