-
Notifications
You must be signed in to change notification settings - Fork 4
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
Lot of unsafe code could probably be replaced by safe code without perf. impact #18
Comments
Hey @Ten0, I am on your side on this. I implemented the linear version of this algorithm in safe Rust, and proposed it to the standard library. I am now waiting for it to be merged. For your information, I didn't take the time to check the performance impact, fortunately, I have an important set of benchmarks. |
Hello! |
Hey @Ten0, Sorry about that, I just published version 0.3.0 which is the real version that contains the changes you are looking for. Don't hesitate to ask me anything if you have any requests about this library. |
Hmm looks like linear group by key has the same issue that could be fixed in the same way, no? Or even more simply, by making |
This could be the case, but I don't have time right now. Maybe you can propose a pull request? I am pretty sure it will not be breaking. |
Looking at the source code:
https://docs.rs/slice-group-by/0.2.6/src/slice_group_by/linear_group/linear_group_by.rs.html#131-136
It seems this crate makes extensive use of
unsafe
.However, it also looks like this
unsafe
is unnecessary as it creates no performance improvement:Representation with the two pointers is exactly the memory representation of a slice, so it looks like this:
could be replaced by this:
while this:
could be rewritten using
for (i,s) in self.elements_left.windows(2).enumerate()
andslice::split_at
/slice::split_at_mut
.(and obviously this:
by this:
)
I don't think this change would create additional runtime cost, as most double-bounds-checking (or constant-bounds-checking in particular with the constants
2
and1
here) usually gets optimized-out by the compiler, and I would feel much more comfortable using this crate, as I wouldn't like to introduce so much unsafe to our codebase for such a simple algorithm.The text was updated successfully, but these errors were encountered: