Rollup merge of #37622 - ollie27:cstring, r=alexcrichton

Slightly optimise CString

Avoid a reallocation in CString::from and CStr::to_owned.
This commit is contained in:
Eduard-Mihai Burtescu 2016-11-09 20:51:18 +02:00 committed by GitHub
commit aad4f29f7b

View 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() }
}
}