netudima commented on code in PR #4415:
URL: https://github.com/apache/cassandra/pull/4415#discussion_r2515119413


##########
src/java/org/apache/cassandra/utils/memory/NativeAllocator.java:
##########
@@ -104,30 +104,98 @@ public DecoratedKey clone(DecoratedKey key, OpOrder.Group 
writeOp)
     @Override
     public Cloner cloner(Group opGroup)
     {
-        return new Cloner()
-                {
-
-                    @Override
-                    public DecoratedKey clone(DecoratedKey key)
-                    {
-                        return NativeAllocator.this.clone(key, opGroup);
-                    }
-
-                    @Override
-                    public Clustering<?> clone(Clustering<?> clustering)
-                    {
-                        if (clustering != Clustering.STATIC_CLUSTERING)
-                            return new NativeClustering(NativeAllocator.this, 
opGroup, clustering);
-
-                        return Clustering.STATIC_CLUSTERING;
-                    }
-
-                    @Override
-                    public Cell<?> clone(Cell<?> cell)
-                    {
-                        return new NativeCell(NativeAllocator.this, opGroup, 
cell);
-                    }
-                };
+        return new NativeCloner(this, opGroup);
+    }
+
+    private static class NativeCloner implements Cloner, AddressBasedAllocator
+    {
+        private final NativeAllocator allocator;
+        private final Group opGroup;
+
+        private final long address;
+        private final int limit;
+        private int offset = 0;
+
+        private NativeCloner(NativeAllocator allocator, Group opGroup)
+        {
+            this(allocator, opGroup, 0);
+        }
+
+        private NativeCloner(NativeAllocator allocator, Group opGroup, int 
size)
+        {
+            this.allocator = allocator;
+            this.opGroup = opGroup;
+            this.limit = size;
+            this.address = size > 0 ? allocator.allocate(size, opGroup) : -1;
+        }
+
+        @Override
+        public DecoratedKey clone(DecoratedKey key)
+        {
+            return allocator.clone(key, opGroup);
+        }
+
+        @Override
+        public Clustering<?> clone(Clustering<?> clustering)
+        {
+            if (clustering != Clustering.STATIC_CLUSTERING)
+                return new NativeClustering(this, opGroup, clustering);
+
+            return Clustering.STATIC_CLUSTERING;

Review Comment:
   the form is actually taken as is from the original logic which we had before 
(it is shown as changed in the diff just because I've converted the anonymous 
class to an explicit nested one)
   but I do not see an issue to apply the change if you think it still makes 
sense (for me both styles are equally readable)



-- 
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