improve performance of span_iterator w/ clang by carsonRadtke · Pull Request #1166 · microsoft/GSL (original) (raw)

Issue: #1165

Before this PR, the range-for loop was ~3300x slower. After this PR, it is ~1.005x slower

The clang optimizer is very good at optimizing current != end, so we changed to this idiom. This moves the Expects assertion into the constructor instead of on the hot-path which is called whenever either operator++ or operator* is called.

Note: The codegen for the assertion is still a missed optimization, but less worrisome as it only happens once per iterator.