4 ms·
If you want to omit a bounds check, the compiler needs to know that the length of the array covers the upper bound of the loop, right?
by wtetzner 6y ago
If you want to omit a bounds check, the compiler needs to know that the length of the array covers the upper bound of the loop, right?
- nybble41 6y agoIf the array length is known to be strictly less than 255 then there is definitely an out-of-bounds access inside the loop, but since this is a panic rather than undefined behavior it could matter how many loop iterations are executed before the out of bounds access occurs, so the check can't be omitted. If the array size is definitely greater than or equal to 255 then all the array accesses in the loop will be in bounds and no further bounds check is required.
- wtetzner 6y agoOh, right.