@@ -493,11 +493,11 @@ impl Regex {
493
493
if limit > 0 && i >= limit {
494
494
break
495
495
}
496
- extend_from_slice ( & mut new , & text[ last_match..m. start ( ) ] ) ;
497
- extend_from_slice ( & mut new , & * rep) ;
496
+ new . extend_from_slice ( & text[ last_match..m. start ( ) ] ) ;
497
+ new . extend_from_slice ( & rep) ;
498
498
last_match = m. end ( ) ;
499
499
}
500
- extend_from_slice ( & mut new , & text[ last_match..] ) ;
500
+ new . extend_from_slice ( & text[ last_match..] ) ;
501
501
return Cow :: Owned ( new) ;
502
502
}
503
503
@@ -515,11 +515,11 @@ impl Regex {
515
515
}
516
516
// unwrap on 0 is OK because captures only reports matches
517
517
let m = cap. get ( 0 ) . unwrap ( ) ;
518
- extend_from_slice ( & mut new , & text[ last_match..m. start ( ) ] ) ;
518
+ new . extend_from_slice ( & text[ last_match..m. start ( ) ] ) ;
519
519
rep. replace_append ( & cap, & mut new) ;
520
520
last_match = m. end ( ) ;
521
521
}
522
- extend_from_slice ( & mut new , & text[ last_match..] ) ;
522
+ new . extend_from_slice ( & text[ last_match..] ) ;
523
523
Cow :: Owned ( new)
524
524
}
525
525
}
@@ -980,7 +980,7 @@ impl<'a> Replacer for &'a [u8] {
980
980
981
981
impl < F > Replacer for F where F : FnMut ( & Captures ) -> Vec < u8 > {
982
982
fn replace_append ( & mut self , caps : & Captures , dst : & mut Vec < u8 > ) {
983
- extend_from_slice ( dst , & ( * self ) ( caps) ) ;
983
+ dst . extend_from_slice ( & ( * self ) ( caps) ) ;
984
984
}
985
985
}
986
986
@@ -996,26 +996,10 @@ pub struct NoExpand<'r>(pub &'r [u8]);
996
996
997
997
impl < ' a > Replacer for NoExpand < ' a > {
998
998
fn replace_append ( & mut self , _: & Captures , dst : & mut Vec < u8 > ) {
999
- extend_from_slice ( dst , self . 0 ) ;
999
+ dst . extend_from_slice ( self . 0 ) ;
1000
1000
}
1001
1001
1002
1002
fn no_expansion < ' r > ( & ' r mut self ) -> Option < Cow < ' r , [ u8 ] > > {
1003
1003
Some ( Cow :: Borrowed ( self . 0 ) )
1004
1004
}
1005
1005
}
1006
-
1007
- /// This hopefully has the same performance characteristics as
1008
- /// Vec::extend_from_slice (which was introduced in Rust 1.6), but works on
1009
- /// Rust 1.3.
1010
- ///
1011
- /// N.B. Remove this once we do a semver bump. At that point, we'll bump
1012
- /// required Rust version to at least 1.6.
1013
- fn extend_from_slice ( dst : & mut Vec < u8 > , src : & [ u8 ] ) {
1014
- dst. reserve ( src. len ( ) ) ;
1015
- let dst_len = dst. len ( ) ;
1016
- unsafe { dst. set_len ( dst_len + src. len ( ) ) ; }
1017
- let mut dst = & mut dst[ dst_len..dst_len + src. len ( ) ] ;
1018
- for i in 0 ..src. len ( ) {
1019
- dst[ i] = src[ i] ;
1020
- }
1021
- }
0 commit comments