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
So I would expect the new version to outperform the unsafe version on debug builds, and match the unsafe version with optimizations
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
So I would expect the new version to outperform the unsafe version on debug builds, and match the unsafe version with optimizations