Skip to content

Commit

Permalink
Slightly optimise CString
Browse files Browse the repository at this point in the history
Avoid a reallocation in CString::from and CStr::to_owned.
  • Loading branch information
ollie27 committed Nov 8, 2016
1 parent acfe959 commit 18f5f99
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/libstd/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
}
}

Expand Down

0 comments on commit 18f5f99

Please sign in to comment.