Circular increment: Which is "better"?
- by Helper Method
When you have a circular buffer represented as an array, and you need the index to wraparound (i.e., when you reach the highest possible index and increment it), is it "better" to:
return (i++ == buffer.length) ? 0: i;
Or
return i++ % buffer.length;
Has using the modulo operator any drawbacks? Is it less readable than the first solution?