diff options
| author | Oliver Middleton <olliemail27@gmail.com> | 2016-11-08 16:55:24 +0000 |
|---|---|---|
| committer | Oliver Middleton <olliemail27@gmail.com> | 2016-11-08 16:55:24 +0000 |
| commit | 18f5f9960f8db867ce7f716fc0f40b9b65c12a73 (patch) | |
| tree | 845116833caf5055743db9ff76f8eacf4f8f82db /src/libstd/ffi | |
| parent | acfe959701ce221af37516401726be6d2814cc3f (diff) | |
| download | rust-18f5f9960f8db867ce7f716fc0f40b9b65c12a73.tar.gz rust-18f5f9960f8db867ce7f716fc0f40b9b65c12a73.zip | |
Slightly optimise CString
Avoid a reallocation in CString::from and CStr::to_owned.
Diffstat (limited to 'src/libstd/ffi')
| -rw-r--r-- | src/libstd/ffi/c_str.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 3ad5b5627d3..d1b8fcd7440 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -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() } } } |
