File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -1464,7 +1464,7 @@ object ByteVector extends ByteVectorCompanionCrossPlatform {
1464
1464
asByteBufferUnsafe(offset, size).asReadOnlyBuffer()
1465
1465
1466
1466
override def asByteBufferUnsafe (offset : Long , size : Int ): ByteBuffer = {
1467
- val b = buf
1467
+ val b = buf.duplicate()
1468
1468
if (offset == 0 && b.position() == 0 && size == b.remaining()) b
1469
1469
else {
1470
1470
b.position(offset.toInt)
Original file line number Diff line number Diff line change @@ -487,6 +487,18 @@ class ByteVectorTest extends BitsSuite {
487
487
assert(arr eq ByteVector .view(ByteBuffer .wrap(arr)).drop(1 ).toByteBufferUnsafe.array)
488
488
}
489
489
490
+ test(" toByteBufferUnsafe has independent position+limit" ) {
491
+ val bv = ByteVector .view(ByteBuffer .wrap(" Hello, world!" .getBytes))
492
+ val bb1 = bv.toByteBufferUnsafe
493
+ assertEquals(bb1.position(), 0 )
494
+ assertEquals(bb1.limit(), 13 )
495
+ val bb2 = bv.toByteBufferUnsafe
496
+ bb2.position(1 )
497
+ bb2.limit(2 )
498
+ assertEquals(bb1.position(), 0 )
499
+ assertEquals(bb1.limit(), 13 )
500
+ }
501
+
490
502
property(" dropping from a view is consistent with dropping from a strict vector" ) {
491
503
forAll { (b : ByteVector , n0 : Long ) =>
492
504
val view = ByteVector .view(b.toArray)
You can’t perform that action at this time.
0 commit comments