Don't allocate in ThreadLocalReadAheadBuffer#close()

Patch by Jordan West; reviewed by [committers] for CASSANDRA-20551
This commit is contained in:
Jordan West 2025-04-13 12:26:55 -07:00
parent 17cb89208c
commit 446d0c1026
1 changed files with 11 additions and 8 deletions

View File

@ -131,18 +131,21 @@ public final class ThreadLocalReadAheadBuffer
public void clear(boolean deallocate)
{
Block block = getBlock();
// avoid calling block() here to reduce unintended allocations
Block block = blockMap.get().get(channel.filePath());
if (block == null)
return;
block.index = -1;
if (block.buffer == null)
return;
ByteBuffer blockBuffer = block.buffer;
if (blockBuffer != null)
blockBuffer.clear();
if (deallocate)
{
blockBuffer.clear();
if (deallocate)
{
FileUtils.clean(blockBuffer);
block.buffer = null;
}
FileUtils.clean(blockBuffer);
block.buffer = null;
}
}