josh-mckenzie commented on code in PR #1954:
URL: https://github.com/apache/cassandra/pull/1954#discussion_r1041255144


##########
src/java/org/apache/cassandra/io/util/DataOutputBuffer.java:
##########
@@ -61,32 +61,62 @@ private enum AllocationType { DIRECT, ONHEAP }
         @Override
         protected DataOutputBuffer initialValue()
         {
-            return new DataOutputBuffer()
-            {
-                @Override
-                public void close()
-                {
-                    if (buffer != null && buffer.capacity() <= 
MAX_RECYCLE_BUFFER_SIZE)
-                    {
-                        buffer.clear();
-                    }
-                    else
-                    {
-                        setBuffer(allocate(DEFAULT_INITIAL_BUFFER_SIZE));
-                    }
-                }
-
-                @Override
-                protected ByteBuffer allocate(int size)
-                {
-                    return ALLOCATION_TYPE == AllocationType.DIRECT ?
-                           ByteBuffer.allocateDirect(size) :
-                           ByteBuffer.allocate(size);
-                }
-            };
+            return new LimitingScratchBuffer();
         }
     };
 
+    /**
+     * Returns a {@link DataOutputBuffer} that is limited to a capacity of 
{@code limit} bytes.
+     * A {@code limit} of 0 means unlimited.
+     */
+    public static DataOutputBuffer limitedScratchBuffer(long limit)
+    {
+        LimitingScratchBuffer dob = (LimitingScratchBuffer) 
scratchBuffer.get();

Review Comment:
   A lot clearer now w/the new init + overrides on scratchBuffer init. 👍 



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