Remove unneeded unsafe in data_directories.rs #261
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request replaces get_unchecked calls with direct indexing ( [] ). This removes a bunch of unsafe blocks
As far as I can tell, this should not affect optimized code: Since rust statically knows the size of the array, it should be able to elide the bounds checks
This godbolt link shows how both the version with and without the unsafe are compiled to the same function with opt-level=3. This is the same example without the derives adding noise to the output
What I found interesting is, according to this godbolt link when compiling without optimizations, rust also elides the bounds checks for the indexing version, and the get_unchecked version has to call the get_unchecked function which does not get inlined
![imagen](https://user-images.githubusercontent.com/24706838/107867089-4fccd980-6e56-11eb-8fbb-b729d337fd7c.png)
So I would expect the new version to outperform the unsafe version on debug builds, and match the unsafe version with optimizations