about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-06-20 23:20:21 +0200
committerMazdak Farrokhzad <twingoow@gmail.com>2019-06-20 23:20:21 +0200
commit6b8417b55c59f3412e97131fd1f99e34bdd8f5d2 (patch)
tree7fa792991dc7fee7dc6809f5ad02af67983ab214
parent85978d028ad6edb1530c494682c05b46f26900f6 (diff)
downloadrust-6b8417b55c59f3412e97131fd1f99e34bdd8f5d2.tar.gz
rust-6b8417b55c59f3412e97131fd1f99e34bdd8f5d2.zip
shared_from_iter: Clarify slice::Iter specialization impl.
-rw-r--r--src/liballoc/rc.rs10
-rw-r--r--src/liballoc/sync.rs10
2 files changed, 16 insertions, 4 deletions
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<T, I: iter::TrustedLen<Item = T>> RcFromIter<T, I> 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<T: Clone> From<&[T]> for Rc<[T]>`
-        // which will use `ptr::copy_nonoverlapping`.
+        // Delegate to `impl<T: Clone> 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<T, I: iter::TrustedLen<Item = T>> ArcFromIter<T, I> 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<T: Clone> From<&[T]> for Arc<[T]>`
-        // which will use `ptr::copy_nonoverlapping`.
+        // Delegate to `impl<T: Clone> 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()
     }
 }