-
Notifications
You must be signed in to change notification settings - Fork 14k
Cleanup strs #7996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup strs #7996
Conversation
src/libstd/str.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably have a warning about maintaining the invariant that the string is valid UTF8, and should definitely take &mut self rather than &self.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching that. I'll add the &mut self and a warning.
|
@huonw: Updated the pull request address your suggestion, and also added a couple more cleanup functions. |
|
I would think (The whole matter of null termination remains, to this day, contentious. As you know, in #7235) |
These uses are assuming the strings are null terminated, so it should be using `as_c_str` instead of `as_buf`
This eliminates a copy and fixes a FIXME.
|
@graydon: Updated the pull request to add |
This is a cleanup pull request that does: * removes `os::as_c_charp` * moves `str::as_buf` and `str::as_c_str` into `StrSlice` * converts some functions from `StrSlice::as_buf` to `StrSlice::as_c_str` * renames `StrSlice::as_buf` to `StrSlice::as_imm_buf` (and adds `StrSlice::as_mut_buf` to match `vec.rs`. * renames `UniqueStr::as_bytes_with_null_consume` to `UniqueStr::to_bytes` * and other misc cleanups and minor optimizations
…arth Add test case for RESULT_MAP_OR_INTO_OPTION just added test case for RESULT_MAP_OR_INTO_OPTION. changelog: none
This is a cleanup pull request that does:
os::as_c_charpstr::as_bufandstr::as_c_strintoStrSliceStrSlice::as_buftoStrSlice::as_c_strStrSlice::as_buftoStrSlice::as_imm_buf(and addsStrSlice::as_mut_bufto matchvec.rs.UniqueStr::as_bytes_with_null_consumetoUniqueStr::to_bytes