What is the best way to return a view to an ArraySeq?

135 Views Asked by At

Ideally when working from an IndexedSeqView over an ArraySeq, there should be only one array copy (or at least only one new array allocated) when converting the view back to an ArraySeq after some manipulation.
What is the most performant way to get back to an ArraySeq?

A couple options that come to mind:

ArraySeq.unsafeWrapArray(view.toArray)

seems promising, but does .toArray know the view is over an array and can use fast array copies to populate the new array?

ArraySeq.from(view)

I'm guessing this is O(n)

2

There are 2 best solutions below

1
Jasper-M On

The standard way would be

view.to(ArraySeq)
1
Jarrod Baker On

Looking at the documentation, the recommended way is calling view.force to evaluate the transformations for the collection.