Specialize toArray for performance.