yugan95 commented on PR #7621:
URL: https://github.com/apache/paimon/pull/7621#issuecomment-4447284916

   @leaves12138 Thanks for the review! All three points are addressed in the 
updated commit:
   
   1. Exact capacity when doubling exceeds max
   
   When requiredCapacity > MAX_ARRAY_SIZE >> 1, the code now allocates the 
exact required capacity instead of MAX_ARRAY_SIZE. This avoids the unnecessary 
~2GB allocation for a ~1.1GB request.
   
   2. Long arithmetic for required capacity
   
   reserveBytes now accepts long. The callers compute required capacity with 
long arithmetic:
   
   putByteArray: (long) bytesAppended + length
   fill: (long) start.length * value.length
   If the result exceeds MAX_ARRAY_SIZE, a clear RuntimeException is thrown 
before any downcast to int, so an int overflow can never silently bypass the 
guard.
   
   3. Extracted helper + edge-case tests
   
   The capacity-growth logic is extracted into a package-private static int 
calculateNewBytesCapacity(long) method, tested directly with 7 new cases 
covering:
   
   Normal doubling for small values
   Boundary at exactly MAX_ARRAY_SIZE >> 1 (still doubles)
   Just above MAX_ARRAY_SIZE >> 1 (returns exact capacity, not MAX_ARRAY_SIZE)
   Exactly MAX_ARRAY_SIZE (returns exact)
   Above MAX_ARRAY_SIZE (throws)
   Simulated int-overflow values via long (throws)
   No huge allocations needed — all edge cases are tested purely through the 
helper.


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

Reply via email to