Use each_index instead of each_with_index to avoid object allocations.