Forward OsStr::clone_into to the inner Vec

Despite OS differences, they're all just `Vec<u8>` inside, so we can
just forward `clone_into` calls to that optimized implementation.
This commit is contained in:
Josh Stone 2020-03-20 15:46:40 -07:00
parent b80fa76ee0
commit f854070bb8
4 changed files with 13 additions and 2 deletions

View File

@ -1120,8 +1120,7 @@ impl ToOwned for OsStr {
self.to_os_string() self.to_os_string()
} }
fn clone_into(&self, target: &mut OsString) { fn clone_into(&self, target: &mut OsString) {
target.clear(); self.inner.clone_into(&mut target.inner)
target.push(self);
} }
} }

View File

@ -159,6 +159,10 @@ impl Slice {
Buf { inner: buf } Buf { inner: buf }
} }
pub fn clone_into(&self, buf: &mut Buf) {
self.inner.clone_into(&mut buf.inner)
}
#[inline] #[inline]
pub fn into_box(&self) -> Box<Slice> { pub fn into_box(&self) -> Box<Slice> {
unsafe { mem::transmute(self.inner.into_box()) } unsafe { mem::transmute(self.inner.into_box()) }

View File

@ -173,6 +173,10 @@ impl Slice {
Buf { inner: self.inner.to_vec() } Buf { inner: self.inner.to_vec() }
} }
pub fn clone_into(&self, buf: &mut Buf) {
self.inner.clone_into(&mut buf.inner)
}
#[inline] #[inline]
pub fn into_box(&self) -> Box<Slice> { pub fn into_box(&self) -> Box<Slice> {
let boxed: Box<[u8]> = self.inner.into(); let boxed: Box<[u8]> = self.inner.into();

View File

@ -613,6 +613,10 @@ impl Wtf8 {
} }
} }
pub fn clone_into(&self, buf: &mut Wtf8Buf) {
self.bytes.clone_into(&mut buf.bytes)
}
/// Boxes this `Wtf8`. /// Boxes this `Wtf8`.
#[inline] #[inline]
pub fn into_box(&self) -> Box<Wtf8> { pub fn into_box(&self) -> Box<Wtf8> {