Be more precise when copying the queue buffer.

Work out the logic more precisely to only copy exactly the elements we need.
Avoids an entire call to copy() when the queue doesn't wrap, and avoids copying
dead elements even when it does. Small but measurable performance improvement on
my benchmarks.