Merge "Avoid expensive array_shift where possible"