-
Notifications
You must be signed in to change notification settings - Fork 604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chunk support for ArraySeq #1905
Conversation
case a: collection.mutable.ArraySeq[O] => arraySeq(a) | ||
case a: collection.immutable.ArraySeq[O] => arraySeq(a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have replaced the previous implementation of this behaviour via ArrayBackedSeq
(now deleted).
copyToArray(array) | ||
ArraySeq.unsafeWrapArray[O2](array) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be the most efficient way to construct an ArraySeq
, given it will often take advantage of System.arraycopy
. I might be missing something, though, so I'm open to feedback if there are better ways to do this.
|
||
def toArraySeqUntagged: ArraySeq[O] = | ||
self match { | ||
case knownType: Chunk.KnownElementType[O] => toArraySeq[O](knownType.elementClassTag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We attempt to specialise the ArraySeq
even if there is no ClassTag
available.
|
||
trait ChunkCompanionPlatform { self: Chunk.type => | ||
|
||
// The array casts below are safe because the array constructor will check for primative vs boxed arrays |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment replaces the now-deleted comment here in Chunk
.
Removing the |
import scala.collection.immutable | ||
import scala.reflect.ClassTag | ||
|
||
trait ChunkPlatform[+O] { self: Chunk[O] => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this trait and it’s companion private[fs2]
both here and in 2.13 file? Otherwise looks ready for merge. Thanks!
Thanks @mpilquist! This one should be good to go once the build completes. |
This PR adds support for immutable and mutable
ArraySeq
s forChunk
. Conversions in both directions are provided. This PR follows on from #1899.Constructing a
Chunk
fromArraySeq
The
Chunk.arraySeq
factory method constructs aChunk
by wrapping the underlying array. This reproduces the behaviour previously implemented inArrayBackedSeq
.Constructing an
ArraySeq
from aChunk
Why provide specialised support for
ArraySeq
?The immutable
ArraySeq
is newly added in Scala 2.13. It is an immutable wrapper over a bare array with specialised implementations for primitives. As such it is well suited to the kinds of performance-sensitive uses for which fs2 is commonly used.