Skip to content

Commit 28791f6

Browse files
committed
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.
1 parent 9ab454a commit 28791f6

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

src/libstd/ffi/os_str.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -952,8 +952,7 @@ impl ToOwned for OsStr {
952952
self.to_os_string()
953953
}
954954
fn clone_into(&self, target: &mut OsString) {
955-
target.clear();
956-
target.push(self);
955+
self.inner.clone_into(&mut target.inner)
957956
}
958957
}
959958

src/libstd/sys/windows/os_str.rs

+4
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ impl Slice {
147147
Buf { inner: buf }
148148
}
149149

150+
pub fn clone_into(&self, buf: &mut Buf) {
151+
self.inner.clone_into(&mut buf.inner)
152+
}
153+
150154
#[inline]
151155
pub fn into_box(&self) -> Box<Slice> {
152156
unsafe { mem::transmute(self.inner.into_box()) }

src/libstd/sys_common/os_str_bytes.rs

+4
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ impl Slice {
162162
Buf { inner: self.inner.to_vec() }
163163
}
164164

165+
pub fn clone_into(&self, buf: &mut Buf) {
166+
self.inner.clone_into(&mut buf.inner)
167+
}
168+
165169
#[inline]
166170
pub fn into_box(&self) -> Box<Slice> {
167171
let boxed: Box<[u8]> = self.inner.into();

src/libstd/sys_common/wtf8.rs

+4
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,10 @@ impl Wtf8 {
613613
}
614614
}
615615

616+
pub fn clone_into(&self, buf: &mut Wtf8Buf) {
617+
self.bytes.clone_into(&mut buf.bytes)
618+
}
619+
616620
/// Boxes this `Wtf8`.
617621
#[inline]
618622
pub fn into_box(&self) -> Box<Wtf8> {

0 commit comments

Comments
 (0)