|
|
|
|
|
by scoutt
2378 days ago
|
|
But in this case the overhead may come from calling get_unchecked() for every array access, is this correct? Unless the function it's inlined and does a quantifiable amount of work (for a given arch), but this may also have an impact on code size. In a way or another, there should be a trade-off for accessing array elements (a very common operation). I don't know how all of this can be coupled with the embedded ecosystem we are used to work with. |
|
Here, rustc is able to see that we always have a first element, and will actually completely remove the unchecked one, and replace the body with the "checked" one, which has no checks.
For some reason, I can't get it to show the assembly for just the two functions; it always optimzies everything out. Putting it on the rust playground says this:
as you can see, it gets super inlined, and does no work, compared to the bound checked version.