4 ms·
..yep, true, completely slipped my mind. So modulo is just trivially always the bad choice. Even for arbitrary indexing "tmp=head+index; buffer[(tmp >= capacit
by dzaima 2y ago
..yep, true, completely slipped my mind. So modulo is just trivially always the bad choice.
Even for arbitrary indexing "tmp=head+index; buffer[(tmp >= capacity) ? tmp - capacity : tmp]" or so is gonna be better. (assuming the compiler compiles it to something branchless. Or, probably even if it doesn't - division might end up slower than the worst-case of 50% misprediction! And for sequential indexing it's even gonna be predictable.)