← Back to context

Comment by secondcoming

8 hours ago

If you enforce that the buffer size is a power of 2 you just use a mask to do the

    if (next_head == buffer.size())
        next_head = 0;

part

If it's a power of two, you don't need the branch at all. Let the unsigned index wrap.

Indeed that's true. That extra constraint enables further optimization

It's mentioned in the post, but worth reiterating!