optimize loop to branch

In this context (where this commit changes), new value of bi is
MIN(bi, self->bhend - 1). This is clearly waste of time to use loop.