Skip to content

Commit aad4f29

Browse files
authored
Rollup merge of rust-lang#37622 - ollie27:cstring, r=alexcrichton
Slightly optimise CString Avoid a reallocation in CString::from and CStr::to_owned.
2 parents 5ebd7c5 + 18f5f99 commit aad4f29

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/libstd/ffi/c_str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ impl ToOwned for CStr {
686686
type Owned = CString;
687687

688688
fn to_owned(&self) -> CString {
689-
unsafe { CString::from_vec_unchecked(self.to_bytes().to_vec()) }
689+
CString { inner: self.to_bytes_with_nul().to_vec().into_boxed_slice() }
690690
}
691691
}
692692

0 commit comments

Comments
 (0)