File tree 1 file changed +18
-1
lines changed
1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -1571,7 +1571,24 @@ impl<T> Vec<T> {
1571
1571
#[ stable( feature = "extend_ref" , since = "1.2.0" ) ]
1572
1572
impl < ' a , T : ' a + Copy > Extend < & ' a T > for Vec < T > {
1573
1573
fn extend < I : IntoIterator < Item = & ' a T > > ( & mut self , iter : I ) {
1574
- self . extend ( iter. into_iter ( ) . cloned ( ) ) ;
1574
+ <I as SpecExtendVec < T > >:: extend_vec ( iter, self ) ;
1575
+ }
1576
+ }
1577
+
1578
+ // helper trait for specialization of Vec's Extend impl
1579
+ trait SpecExtendVec < T > {
1580
+ fn extend_vec ( self , vec : & mut Vec < T > ) ;
1581
+ }
1582
+
1583
+ impl < ' a , T : ' a + Copy , I : IntoIterator < Item =& ' a T > > SpecExtendVec < T > for I {
1584
+ default fn extend_vec ( self , vec : & mut Vec < T > ) {
1585
+ vec. extend ( self . into_iter ( ) . cloned ( ) ) ;
1586
+ }
1587
+ }
1588
+
1589
+ impl < ' a , T : Copy > SpecExtendVec < T > for & ' a [ T ] {
1590
+ fn extend_vec ( self , vec : & mut Vec < T > ) {
1591
+ vec. extend_from_slice ( self ) ;
1575
1592
}
1576
1593
}
1577
1594
You can’t perform that action at this time.
0 commit comments