@@ -558,29 +558,23 @@ public static AbstractMemorySegmentImpl ofBuffer(Buffer bb) {
558
558
} else {
559
559
bufferScope = MemorySessionImpl .createHeap (bufferRef (bb ));
560
560
}
561
+ long off = bbAddress + ((long )pos << scaleFactor );
562
+ long len = (long )size << scaleFactor ;
561
563
if (base != null ) {
562
564
return switch (base ) {
563
- case byte [] __ ->
564
- new HeapMemorySegmentImpl .OfByte (bbAddress + (pos << scaleFactor ), base , size << scaleFactor , readOnly , bufferScope );
565
- case short [] __ ->
566
- new HeapMemorySegmentImpl .OfShort (bbAddress + (pos << scaleFactor ), base , size << scaleFactor , readOnly , bufferScope );
567
- case char [] __ ->
568
- new HeapMemorySegmentImpl .OfChar (bbAddress + (pos << scaleFactor ), base , size << scaleFactor , readOnly , bufferScope );
569
- case int [] __ ->
570
- new HeapMemorySegmentImpl .OfInt (bbAddress + (pos << scaleFactor ), base , size << scaleFactor , readOnly , bufferScope );
571
- case float [] __ ->
572
- new HeapMemorySegmentImpl .OfFloat (bbAddress + (pos << scaleFactor ), base , size << scaleFactor , readOnly , bufferScope );
573
- case long [] __ ->
574
- new HeapMemorySegmentImpl .OfLong (bbAddress + (pos << scaleFactor ), base , size << scaleFactor , readOnly , bufferScope );
575
- case double [] __ ->
576
- new HeapMemorySegmentImpl .OfDouble (bbAddress + (pos << scaleFactor ), base , size << scaleFactor , readOnly , bufferScope );
577
- default -> throw new AssertionError ("Cannot get here" );
565
+ case byte [] _ -> new HeapMemorySegmentImpl .OfByte (off , base , len , readOnly , bufferScope );
566
+ case short [] _ -> new HeapMemorySegmentImpl .OfShort (off , base , len , readOnly , bufferScope );
567
+ case char [] _ -> new HeapMemorySegmentImpl .OfChar (off , base , len , readOnly , bufferScope );
568
+ case int [] _ -> new HeapMemorySegmentImpl .OfInt (off , base , len , readOnly , bufferScope );
569
+ case float [] _ -> new HeapMemorySegmentImpl .OfFloat (off , base , len , readOnly , bufferScope );
570
+ case long [] _ -> new HeapMemorySegmentImpl .OfLong (off , base , len , readOnly , bufferScope );
571
+ case double [] _ -> new HeapMemorySegmentImpl .OfDouble (off , base , len , readOnly , bufferScope );
572
+ default -> throw new AssertionError ("Cannot get here" );
578
573
};
579
574
} else if (unmapper == null ) {
580
- return new NativeMemorySegmentImpl (bbAddress + ( pos << scaleFactor ), size << scaleFactor , readOnly , bufferScope );
575
+ return new NativeMemorySegmentImpl (off , len , readOnly , bufferScope );
581
576
} else {
582
- // we can ignore scale factor here, a mapped buffer is always a byte buffer, so scaleFactor == 0.
583
- return new MappedMemorySegmentImpl (bbAddress + pos , unmapper , size , readOnly , bufferScope );
577
+ return new MappedMemorySegmentImpl (off , unmapper , len , readOnly , bufferScope );
584
578
}
585
579
}
586
580
@@ -721,13 +715,10 @@ public static long mismatch(MemorySegment srcSegment, long srcFromOffset, long s
721
715
722
716
private static int getScaleFactor (Buffer buffer ) {
723
717
return switch (buffer ) {
724
- case ByteBuffer __ -> 0 ;
725
- case CharBuffer __ -> 1 ;
726
- case ShortBuffer __ -> 1 ;
727
- case IntBuffer __ -> 2 ;
728
- case FloatBuffer __ -> 2 ;
729
- case LongBuffer __ -> 3 ;
730
- case DoubleBuffer __ -> 3 ;
718
+ case ByteBuffer _ -> 0 ;
719
+ case CharBuffer _ , ShortBuffer _ -> 1 ;
720
+ case IntBuffer _ , FloatBuffer _ -> 2 ;
721
+ case LongBuffer _ , DoubleBuffer _ -> 3 ;
731
722
};
732
723
}
733
724
0 commit comments