ring-buffer: move big if statement down