]> git.lizzy.rs Git - rust.git/commitdiff
Slightly optimise CString
authorOliver Middleton <olliemail27@gmail.com>
Tue, 8 Nov 2016 16:55:24 +0000 (16:55 +0000)
committerOliver Middleton <olliemail27@gmail.com>
Tue, 8 Nov 2016 16:55:24 +0000 (16:55 +0000)
Avoid a reallocation in CString::from and CStr::to_owned.

src/libstd/ffi/c_str.rs

index 3ad5b5627d319700f26ee91251b25bd4a280e7f9..d1b8fcd74400310323417f0e51c97a0c6a981405 100644 (file)
@@ -686,7 +686,7 @@ impl ToOwned for CStr {
     type Owned = CString;
 
     fn to_owned(&self) -> CString {
-        unsafe { CString::from_vec_unchecked(self.to_bytes().to_vec()) }
+        CString { inner: self.to_bytes_with_nul().to_vec().into_boxed_slice() }
     }
 }