From 8773ac1311d3e880ef8696f39275d53c616acdec Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Mon, 6 Nov 2023 23:48:24 +0000 Subject: [PATCH 1/2] Use `toByteBufferUnsafe` in `toArraySlice` --- core/shared/src/main/scala/fs2/Chunk.scala | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/shared/src/main/scala/fs2/Chunk.scala b/core/shared/src/main/scala/fs2/Chunk.scala index 56d925f262..fc8b3b827d 100644 --- a/core/shared/src/main/scala/fs2/Chunk.scala +++ b/core/shared/src/main/scala/fs2/Chunk.scala @@ -1085,9 +1085,7 @@ object Chunk def toByteVector() = bv override def toArraySlice[O2 >: Byte](implicit ct: ClassTag[O2]): Chunk.ArraySlice[O2] = - if (ct.runtimeClass == classOf[Byte]) - Chunk.ArraySlice[Byte](bv.toArrayUnsafe, 0, size).asInstanceOf[Chunk.ArraySlice[O2]] - else super.toArraySlice + Chunk.ByteBuffer(bv.toByteBufferUnsafe).toArraySlice override def toByteBuffer[B >: Byte](implicit ev: B =:= Byte): JByteBuffer = bv.toByteBuffer From 9154dd8e3a66b87c4f5e11f83530e274d313a0e6 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Tue, 7 Nov 2023 00:06:10 +0000 Subject: [PATCH 2/2] Use `view` to avoid `duplicate` --- core/shared/src/main/scala/fs2/Chunk.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/shared/src/main/scala/fs2/Chunk.scala b/core/shared/src/main/scala/fs2/Chunk.scala index fc8b3b827d..c29e7fd3fe 100644 --- a/core/shared/src/main/scala/fs2/Chunk.scala +++ b/core/shared/src/main/scala/fs2/Chunk.scala @@ -1085,7 +1085,7 @@ object Chunk def toByteVector() = bv override def toArraySlice[O2 >: Byte](implicit ct: ClassTag[O2]): Chunk.ArraySlice[O2] = - Chunk.ByteBuffer(bv.toByteBufferUnsafe).toArraySlice + Chunk.ByteBuffer.view(bv.toByteBufferUnsafe).toArraySlice override def toByteBuffer[B >: Byte](implicit ev: B =:= Byte): JByteBuffer = bv.toByteBuffer