Skip to content

Commit a3969c0

Browse files
committed
toByteBuffer optimizations
1 parent 5906fa9 commit a3969c0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

core/shared/src/main/scala/fs2/Chunk.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,15 @@ abstract class Chunk[+O] extends Serializable with ChunkPlatform[O] with ChunkRu
312312
case c: Chunk.ArraySlice[_] if c.values.isInstanceOf[Array[Byte]] =>
313313
JByteBuffer.wrap(c.values.asInstanceOf[Array[Byte]], c.offset, c.length)
314314
case c: Chunk.ByteBuffer =>
315-
val b = c.buf.asReadOnlyBuffer
315+
val b = c.buf.duplicate // share contents, independent position/limit
316316
if (c.offset == 0 && b.position() == 0 && c.size == b.limit()) b
317317
else {
318318
(b: JBuffer).position(c.offset.toInt)
319319
(b: JBuffer).limit(c.offset.toInt + c.size)
320320
b
321321
}
322+
case c: Chunk.ByteVectorChunk =>
323+
c.bv.toByteBuffer
322324
case _ =>
323325
JByteBuffer.wrap(this.asInstanceOf[Chunk[Byte]].toArray, 0, size)
324326
}

0 commit comments

Comments
 (0)