Skip to content

Commit 18f5f99

Browse files
committed
Slightly optimise CString
Avoid a reallocation in CString::from and CStr::to_owned.
1 parent acfe959 commit 18f5f99

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)