about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2020-03-20 15:46:40 -0700
committerJosh Stone <jistone@redhat.com>2020-04-06 18:26:37 -0700
commitf854070bb820501d88d1b029660bfde663595530 (patch)
tree834344f0f196a8aa8733510370c63201fc895fac
parentb80fa76ee0a160fffa04e337b8e33ef655a80649 (diff)
downloadrust-f854070bb820501d88d1b029660bfde663595530.tar.gz
rust-f854070bb820501d88d1b029660bfde663595530.zip
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.
-rw-r--r--src/libstd/ffi/os_str.rs3
-rw-r--r--src/libstd/sys/windows/os_str.rs4
-rw-r--r--src/libstd/sys_common/os_str_bytes.rs4
-rw-r--r--src/libstd/sys_common/wtf8.rs4
4 files changed, 13 insertions, 2 deletions
diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs
index 5e686946f8e..4fde3316973 100644
--- a/src/libstd/ffi/os_str.rs
+++ b/src/libstd/ffi/os_str.rs
@@ -1120,8 +1120,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)
     }
 }
 
diff --git a/src/libstd/sys/windows/os_str.rs b/src/libstd/sys/windows/os_str.rs
index 6aab028873e..2f5fc72ab44 100644
--- a/src/libstd/sys/windows/os_str.rs
+++ b/src/libstd/sys/windows/os_str.rs
@@ -159,6 +159,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()) }
diff --git a/src/libstd/sys_common/os_str_bytes.rs b/src/libstd/sys_common/os_str_bytes.rs
index aa6cc33d831..984c032e2a3 100644
--- a/src/libstd/sys_common/os_str_bytes.rs
+++ b/src/libstd/sys_common/os_str_bytes.rs
@@ -173,6 +173,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();
diff --git a/src/libstd/sys_common/wtf8.rs b/src/libstd/sys_common/wtf8.rs
index fc6614552a9..a98407da448 100644
--- a/src/libstd/sys_common/wtf8.rs
+++ b/src/libstd/sys_common/wtf8.rs
@@ -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> {