with the gcc flag -funswitch-loops one could use a single inline function inside a loop, but that flag can make other code slower as it bloats the code quite a bit in cases unswitching is not worth it.
We could use function specific optimizations but thats compiler specific.
I think this approach is reasonable as the loop is very simple.