Skip to content

Commit f854070

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 b80fa76 commit f854070

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
@@ -1120,8 +1120,7 @@ impl ToOwned for OsStr {
11201120
self.to_os_string()
11211121
}
11221122
fn clone_into(&self, target: &mut OsString) {
1123-
target.clear();
1124-
target.push(self);
1123+
self.inner.clone_into(&mut target.inner)
11251124
}
11261125
}
11271126

src/libstd/sys/windows/os_str.rs

+4
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ impl Slice {
159159
Buf { inner: buf }
160160
}
161161

162+
pub fn clone_into(&self, buf: &mut Buf) {
163+
self.inner.clone_into(&mut buf.inner)
164+
}
165+
162166
#[inline]
163167
pub fn into_box(&self) -> Box<Slice> {
164168
unsafe { mem::transmute(self.inner.into_box()) }

src/libstd/sys_common/os_str_bytes.rs

+4
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ impl Slice {
173173
Buf { inner: self.inner.to_vec() }
174174
}
175175

176+
pub fn clone_into(&self, buf: &mut Buf) {
177+
self.inner.clone_into(&mut buf.inner)
178+
}
179+
176180
#[inline]
177181
pub fn into_box(&self) -> Box<Slice> {
178182
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)