yifan-c commented on code in PR #4013:
URL: https://github.com/apache/cassandra/pull/4013#discussion_r2017630540


##########
src/java/org/apache/cassandra/utils/FastByteOperations.java:
##########
@@ -163,6 +163,7 @@ public static final class UnsafeOperations implements 
ByteOperations
          */
         static final long BYTE_ARRAY_BASE_OFFSET;
         static final long DIRECT_BUFFER_ADDRESS_OFFSET;
+        static final long HEAP_HB_FIELD;

Review Comment:
   nit: append the same suffix, `_OFFSET` to this field.



##########
src/java/org/apache/cassandra/utils/FastByteOperations.java:
##########
@@ -269,16 +271,29 @@ public void copy(ByteBuffer srcBuf, int srcPosition, 
ByteBuffer trgBuf, int trgP
         {
             Object src;
             long srcOffset;
-            if (srcBuf.hasArray())
+
+            // Heap ByteBuffer (Mutable)
+            if (srcBuf.hasArray() && !srcBuf.isReadOnly())

Review Comment:
   nit: `srcBuf.hasArray()` already implies `!srcBuf.isReadOnly()`, the second 
condition is redundant. 



##########
src/java/org/apache/cassandra/utils/FastByteOperations.java:
##########
@@ -269,16 +271,29 @@ public void copy(ByteBuffer srcBuf, int srcPosition, 
ByteBuffer trgBuf, int trgP
         {
             Object src;
             long srcOffset;
-            if (srcBuf.hasArray())
+
+            // Heap ByteBuffer (Mutable)
+            if (srcBuf.hasArray() && !srcBuf.isReadOnly())
             {
                 src = srcBuf.array();
                 srcOffset = BYTE_ARRAY_BASE_OFFSET + srcBuf.arrayOffset();
             }
+            // Read-Only Heap ByteBuffer (Still has hb but read-only)
+            else if (srcBuf.isReadOnly() && !srcBuf.isDirect())
+            {
+                src = theUnsafe.getObject(srcBuf, HEAP_HB_FIELD);
+                srcOffset = BYTE_ARRAY_BASE_OFFSET;
+
+                if (src == null)
+                    throw new IllegalArgumentException("Unsupported ByteBuffer 
type: No backing array and not direct.");

Review Comment:
   nit: feel to me that it is an illegal state?



##########
src/java/org/apache/cassandra/utils/FastByteOperations.java:
##########
@@ -269,16 +271,29 @@ public void copy(ByteBuffer srcBuf, int srcPosition, 
ByteBuffer trgBuf, int trgP
         {
             Object src;
             long srcOffset;
-            if (srcBuf.hasArray())
+
+            // Heap ByteBuffer (Mutable)
+            if (srcBuf.hasArray() && !srcBuf.isReadOnly())
             {
                 src = srcBuf.array();
                 srcOffset = BYTE_ARRAY_BASE_OFFSET + srcBuf.arrayOffset();
             }
+            // Read-Only Heap ByteBuffer (Still has hb but read-only)
+            else if (srcBuf.isReadOnly() && !srcBuf.isDirect())
+            {
+                src = theUnsafe.getObject(srcBuf, HEAP_HB_FIELD);
+                srcOffset = BYTE_ARRAY_BASE_OFFSET;
+
+                if (src == null)
+                    throw new IllegalArgumentException("Unsupported ByteBuffer 
type: No backing array and not direct.");
+            }
+            // Direct ByteBuffer

Review Comment:
   thanks for adding the comments for the conditions. 👍 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to