nit changes, reverting to orginal condition and adding READ_ONLY_HEAP to Generators.

This commit is contained in:
Sunil Ramchandra Pawar 2025-03-27 23:34:22 +05:30
parent 6f413eef87
commit b9ebbfb268
2 changed files with 3 additions and 4 deletions

View File

@ -196,7 +196,6 @@ public class FastByteOperations
{ {
BYTE_ARRAY_BASE_OFFSET = theUnsafe.arrayBaseOffset(byte[].class); BYTE_ARRAY_BASE_OFFSET = theUnsafe.arrayBaseOffset(byte[].class);
DIRECT_BUFFER_ADDRESS_OFFSET = theUnsafe.objectFieldOffset(Buffer.class.getDeclaredField("address")); DIRECT_BUFFER_ADDRESS_OFFSET = theUnsafe.objectFieldOffset(Buffer.class.getDeclaredField("address"));
HEAP_HB_FIELD = theUnsafe.objectFieldOffset(ByteBuffer.class.getDeclaredField("hb")); HEAP_HB_FIELD = theUnsafe.objectFieldOffset(ByteBuffer.class.getDeclaredField("hb"));
} }
catch (Exception e) catch (Exception e)
@ -276,8 +275,8 @@ public class FastByteOperations
// Heap ByteBuffer (Mutable) // Heap ByteBuffer (Mutable)
if (srcBuf.hasArray() && !srcBuf.isReadOnly()) if (srcBuf.hasArray() && !srcBuf.isReadOnly())
{ {
src = theUnsafe.getObject(srcBuf, HEAP_HB_FIELD); src = srcBuf.array();
srcOffset = BYTE_ARRAY_BASE_OFFSET; srcOffset = BYTE_ARRAY_BASE_OFFSET + srcBuf.arrayOffset();
} }
// Read-Only Heap ByteBuffer (Still has hb but read-only) // Read-Only Heap ByteBuffer (Still has hb but read-only)
else if (srcBuf.isReadOnly() && !srcBuf.isDirect()) else if (srcBuf.isReadOnly() && !srcBuf.isDirect())

View File

@ -365,7 +365,7 @@ public final class Generators
public static Gen<ByteBuffer> bytes(int min, int max) public static Gen<ByteBuffer> bytes(int min, int max)
{ {
return bytes(min, max, SourceDSL.arbitrary().constant(BBCases.HEAP)); return bytes(min, max, SourceDSL.arbitrary().pick(BBCases.HEAP, BBCases.READ_ONLY_HEAP));
} }
public static Gen<ByteBuffer> directBytes(int min, int max) public static Gen<ByteBuffer> directBytes(int min, int max)