diff options
| author | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2016-11-09 20:51:18 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-11-09 20:51:18 +0200 |
| commit | aad4f29f7be65f41a55d89f23b27321431e756b8 (patch) | |
| tree | 4ee5c0e0b75e655a9635be6a232cc4e2ee8b1a6f | |
| parent | 5ebd7c50a0b9236af4389b00c97b00a59d9fa747 (diff) | |
| parent | 18f5f9960f8db867ce7f716fc0f40b9b65c12a73 (diff) | |
| download | rust-aad4f29f7be65f41a55d89f23b27321431e756b8.tar.gz rust-aad4f29f7be65f41a55d89f23b27321431e756b8.zip | |
Rollup merge of #37622 - ollie27:cstring, r=alexcrichton
Slightly optimise CString Avoid a reallocation in CString::from and CStr::to_owned.
| -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() } } } |
