Skip to content

Commit 56b8602

Browse files
committed
Merge remote-tracking branch 'upstream/main' into update/cats-effect-3.5.0-RC1
2 parents 0005138 + a70daca commit 56b8602

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ lazy val io = crossProject(JVMPlatform, JSPlatform, NativePlatform)
278278
.nativeSettings(commonNativeSettings)
279279
.nativeSettings(
280280
libraryDependencies ++= Seq(
281-
"com.armanbilge" %%% "epollcat" % "0.1.3" % Test
281+
"com.armanbilge" %%% "epollcat" % "0.1.4" % Test
282282
),
283283
Test / nativeBrewFormulas += "s2n",
284284
Test / envVars ++= Map("S2N_DONT_MLOCK" -> "1")

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

+12-4
Original file line numberDiff line numberDiff line change
@@ -306,30 +306,38 @@ abstract class Chunk[+O] extends Serializable with ChunkPlatform[O] with ChunkRu
306306
case _ => Chunk.ArraySlice(toArray, 0, size)
307307
}
308308

309-
/** Converts this chunk to a `java.nio.ByteBuffer`. */
309+
/** Converts this chunk to a `java.nio.ByteBuffer`.
310+
* @note that even "read-only" interaction with a `ByteBuffer` may increment its `position`,
311+
* so this method should be considered as unsafely allocating mutable state.
312+
*/
310313
def toByteBuffer[B >: O](implicit ev: B =:= Byte): JByteBuffer =
311314
this match {
312315
case c: Chunk.ArraySlice[_] if c.values.isInstanceOf[Array[Byte]] =>
313316
JByteBuffer.wrap(c.values.asInstanceOf[Array[Byte]], c.offset, c.length)
314317
case c: Chunk.ByteBuffer =>
315-
val b = c.buf.asReadOnlyBuffer
318+
val b = c.buf.duplicate // share contents, independent position/limit
316319
if (c.offset == 0 && b.position() == 0 && c.size == b.limit()) b
317320
else {
318321
(b: JBuffer).position(c.offset.toInt)
319322
(b: JBuffer).limit(c.offset.toInt + c.size)
320323
b
321324
}
325+
case c: Chunk.ByteVectorChunk =>
326+
c.bv.toByteBuffer
322327
case _ =>
323328
JByteBuffer.wrap(this.asInstanceOf[Chunk[Byte]].toArray, 0, size)
324329
}
325330

326-
/** Converts this chunk to a `java.nio.CharBuffer`. */
331+
/** Converts this chunk to a `java.nio.CharBuffer`.
332+
* @note that even "read-only" interaction with a `CharBuffer` may increment its position,
333+
* so this method should be considered as unsafely allocating mutable state.
334+
*/
327335
def toCharBuffer[B >: O](implicit ev: B =:= Char): JCharBuffer =
328336
this match {
329337
case c: Chunk.ArraySlice[_] if c.values.isInstanceOf[Array[Char]] =>
330338
JCharBuffer.wrap(c.values.asInstanceOf[Array[Char]], c.offset, c.length)
331339
case c: Chunk.CharBuffer =>
332-
val b = c.buf.asReadOnlyBuffer
340+
val b = c.buf.duplicate // share contents, independent position/limit
333341
if (c.offset == 0 && b.position() == 0 && c.size == b.limit()) b
334342
else {
335343
(b: JBuffer).position(c.offset.toInt)

0 commit comments

Comments
 (0)