You probably should take an explicit array in this function, rather than requiring the array to be expanded, then gathered again, by the runtime.