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:
@@ -686,7 +686,7 @@ impl ToOwned for CStr {
|
|||||||
type Owned = CString;
|
type Owned = CString;
|
||||||
|
|
||||||
fn to_owned(&self) -> 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() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user