diff --git a/src/re_bytes.rs b/src/re_bytes.rs index 55c6322f05..180c12e3a9 100644 --- a/src/re_bytes.rs +++ b/src/re_bytes.rs @@ -493,11 +493,11 @@ impl Regex { if limit > 0 && i >= limit { break } - extend_from_slice(&mut new, &text[last_match..m.start()]); - extend_from_slice(&mut new, &*rep); + new.extend_from_slice(&text[last_match..m.start()]); + new.extend_from_slice(&rep); last_match = m.end(); } - extend_from_slice(&mut new, &text[last_match..]); + new.extend_from_slice(&text[last_match..]); return Cow::Owned(new); } @@ -515,11 +515,11 @@ impl Regex { } // unwrap on 0 is OK because captures only reports matches let m = cap.get(0).unwrap(); - extend_from_slice(&mut new, &text[last_match..m.start()]); + new.extend_from_slice(&text[last_match..m.start()]); rep.replace_append(&cap, &mut new); last_match = m.end(); } - extend_from_slice(&mut new, &text[last_match..]); + new.extend_from_slice(&text[last_match..]); Cow::Owned(new) } } @@ -980,7 +980,7 @@ impl<'a> Replacer for &'a [u8] { impl Replacer for F where F: FnMut(&Captures) -> Vec { fn replace_append(&mut self, caps: &Captures, dst: &mut Vec) { - extend_from_slice(dst, &(*self)(caps)); + dst.extend_from_slice(&(*self)(caps)); } } @@ -996,26 +996,10 @@ pub struct NoExpand<'r>(pub &'r [u8]); impl<'a> Replacer for NoExpand<'a> { fn replace_append(&mut self, _: &Captures, dst: &mut Vec) { - extend_from_slice(dst, self.0); + dst.extend_from_slice(self.0); } fn no_expansion<'r>(&'r mut self) -> Option> { Some(Cow::Borrowed(self.0)) } } - -/// This hopefully has the same performance characteristics as -/// Vec::extend_from_slice (which was introduced in Rust 1.6), but works on -/// Rust 1.3. -/// -/// N.B. Remove this once we do a semver bump. At that point, we'll bump -/// required Rust version to at least 1.6. -fn extend_from_slice(dst: &mut Vec, src: &[u8]) { - dst.reserve(src.len()); - let dst_len = dst.len(); - unsafe { dst.set_len(dst_len + src.len()); } - let mut dst = &mut dst[dst_len..dst_len + src.len()]; - for i in 0..src.len() { - dst[i] = src[i]; - } -}