Skip to content

Commit

Permalink
Forward OsStr::clone_into to the inner Vec
Browse files Browse the repository at this point in the history
Despite OS differences, they're all just `Vec<u8>` inside, so we can
just forward `clone_into` calls to that optimized implementation.
  • Loading branch information
cuviper committed Mar 20, 2020
1 parent 9ab454a commit 28791f6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/libstd/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,8 +952,7 @@ impl ToOwned for OsStr {
self.to_os_string()
}
fn clone_into(&self, target: &mut OsString) {
target.clear();
target.push(self);
self.inner.clone_into(&mut target.inner)
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/libstd/sys/windows/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ impl Slice {
Buf { inner: buf }
}

pub fn clone_into(&self, buf: &mut Buf) {
self.inner.clone_into(&mut buf.inner)
}

#[inline]
pub fn into_box(&self) -> Box<Slice> {
unsafe { mem::transmute(self.inner.into_box()) }
Expand Down
4 changes: 4 additions & 0 deletions src/libstd/sys_common/os_str_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ impl Slice {
Buf { inner: self.inner.to_vec() }
}

pub fn clone_into(&self, buf: &mut Buf) {
self.inner.clone_into(&mut buf.inner)
}

#[inline]
pub fn into_box(&self) -> Box<Slice> {
let boxed: Box<[u8]> = self.inner.into();
Expand Down
4 changes: 4 additions & 0 deletions src/libstd/sys_common/wtf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,10 @@ impl Wtf8 {
}
}

pub fn clone_into(&self, buf: &mut Wtf8Buf) {
self.bytes.clone_into(&mut buf.bytes)
}

/// Boxes this `Wtf8`.
#[inline]
pub fn into_box(&self) -> Box<Wtf8> {
Expand Down

0 comments on commit 28791f6

Please sign in to comment.