3 ms·
The trend is towards optimizing out bounds checks for at least the easy cases, such as FOR loops. Go does this. Rust should, and probably will soon. That tends
by Animats 11y ago
The trend is towards optimizing out bounds checks for at least the easy cases, such as FOR loops. Go does this. Rust should, and probably will soon. That tends to get most of the inner loops where it really matters, like a matrix multiply. C++ can't do that because the compiler doesn't know that a template-implemented bounds check is a bounds check.
Also, in C++ containers, ".at()" is usually checked, but "[]" is not. So C++ code still regularly has buffer overflow problems.
- logophobia 11y agoRust does optimize iterators, just not random access. You can even turn off the bound checks with get_unchecked, if you really really need unchecked random access.
- steveklabnik 11y ago(and for loops use iterators under the hood)
- pcwalton 11y ago> Go does this. Rust should, and probably will soon. LLVM does optimize these out, and in more cases than Go does. > C++ can't do that because the compiler doesn't know that a template-implemented bounds check is a bounds check. It doesn't need to. SCCP is a very general optimization. GCC and LLVM optimize out bounds checks in more cases than Go can do.