Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion FastMM5.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8104,7 +8104,7 @@ function FastMM_ReallocMem(APointer: Pointer; ANewSize: NativeInt): Pointer;
mov eax, r8d
and eax, (CBlockIsFreeFlag or CIsSmallBlockFlag)
cmp eax, CIsSmallBlockFlag
je FastMM_ReallocMem_ReallocSmallBlock
je @SmallBlock

mov eax, r8d
and eax, (not CHasDebugInfoFlag)
Expand All @@ -8120,6 +8120,29 @@ function FastMM_ReallocMem(APointer: Pointer; ANewSize: NativeInt): Pointer;
xor edx,edx
jmp HandleInvalidFreeMemOrReallocMem

@SmallBlock:
{Inline the common in-place small-block downsize path. This avoids the compiler-generated frame and saved registers
in FastMM_ReallocMem_ReallocSmallBlock on Win64.}
mov r9d, r8d
and r9d, CDropSmallBlockFlagsMask
shl r9d, CSmallBlockSpanOffsetBitShift
mov rax, rcx
and rax, -CMediumBlockAlignment
sub rax, r9
mov rax, TSmallBlockSpanHeader(rax).SmallBlockManager
movzx r9d, TSmallBlockManager(rax).BlockSize
sub r9d, CSmallBlockHeaderSize

{Upsizes and large downsizes use the existing moving path.}
cmp r9, rdx
jb FastMM_ReallocMem_ReallocSmallBlock
lea r10, [rdx * 4 + CSmallBlockDownsizeCheckAdder]
cmp r10, r9
jb FastMM_ReallocMem_ReallocSmallBlock

mov rax, rcx
ret

{$endif}
{$else}
var
Expand Down