-
Notifications
You must be signed in to change notification settings - Fork 613
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
compactUntagged class cast exception #2679
Comments
is any reason to split this logic onto case class ArraySlice[O](values: Array[O], offset: Int, length: Int) extends Chunk[O] {
...
override def compact[O2 >: O]: ArraySlice[O2] = this.asInstanceOf[ArraySlice[O2]]
...
def copyToArray[O2 >: O](xs: Array[O2], start: Int): Unit = System.arraycopy(values, offset, xs, start, length)
...
} or is any reason to change value type on compaction at all? |
@Alexey-Yuferov |
my point was "is compact really needs ClassTag[O2] and ArraySlice ClassTag[O] if we can avoid it like in compactUntagged" def compactUntagged[O2 >: O]: Chunk.ArraySlice[O2] = {
Chunk.ArraySlice(toArray[Any], 0, size).asInstanceOf[Chunk.ArraySlice[O2]]
} why can't it be default implementation for performance without fallback to iterative arrays fill? |
Then you'll never get a primitive array and it will always box. |
Array is a foreign entity for ArraySlice, one can create ArraySlice of primitives: val intArray = Array[Int]
val chunk = Chunk.ArraySlice(intArray) and one does not need ClassTag in this case |
In that example, you need a class tag to construct the array. Once you've constructed an array, you can wrap it in an The PR which addresses this issue (#2680) doesn't introduce any new copying. |
but this one does #2680 |
Okay I see, you're concerned about an extra copy when calling |
@Alexey-Yuferov Please review latest version of #2680 |
@mpilquist it looks good for me |
Fix #2679 - bug in Chunk.compactUntagged when used with empty or singleton chunks
Bonjour!
Reproduction:
Result: java.lang.ClassCastException: class fs2.Chunk$Singleton cannot be cast to class fs2.Chunk$ArraySlice
First was discovered when using evalMapChunk.
Introduced here in v3.1.3 with compactUntagged implementation.
The text was updated successfully, but these errors were encountered: