* small speed improvements

git-svn-id: trunk@2633 -
This commit is contained in:
florian 2006-02-19 16:59:03 +00:00
parent 0089de9428
commit 0cc2b9b16b

View File

@ -851,14 +851,14 @@ end;
function SysGetMem_Fixed(size: ptrint): pointer; function SysGetMem_Fixed(size: ptrint): pointer;
var var
pmc : pmemchunk_fixed; pmc,hp : pmemchunk_fixed;
poc : poschunk; poc : poschunk;
chunkindex : ptrint; chunkindex : ptrint;
begin begin
result:=nil;
{ try to find a block in one of the freelists per size } { try to find a block in one of the freelists per size }
chunkindex := size shr blockshift; chunkindex := size shr blockshift;
pmc := freelists_fixed[chunkindex]; pmc := freelists_fixed[chunkindex];
result:=nil;
{ no free blocks ? } { no free blocks ? }
if not assigned(pmc) then if not assigned(pmc) then
begin begin
@ -869,10 +869,11 @@ begin
{ get a pointer to the block we should return } { get a pointer to the block we should return }
result := pointer(pmc)+sizeof(tmemchunk_fixed_hdr); result := pointer(pmc)+sizeof(tmemchunk_fixed_hdr);
{ update freelist } { update freelist }
freelists_fixed[chunkindex] := pmc^.next_fixed; hp:=pmc^.next_fixed;
if assigned(freelists_fixed[chunkindex]) then
freelists_fixed[chunkindex]^.prev_fixed := nil;
poc := pmc^.poc; poc := pmc^.poc;
freelists_fixed[chunkindex] := hp;
if assigned(hp) then
hp^.prev_fixed := nil;
if (poc^.used = 0) then if (poc^.used = 0) then
freelists_free_chunk[chunkindex] := false; freelists_free_chunk[chunkindex] := false;
inc(poc^.used); inc(poc^.used);
@ -959,12 +960,12 @@ begin
{ calc to multiple of 16 after adding the needed bytes for memchunk header } { calc to multiple of 16 after adding the needed bytes for memchunk header }
if size <= (maxblocksize - sizeof(tmemchunk_fixed_hdr)) then if size <= (maxblocksize - sizeof(tmemchunk_fixed_hdr)) then
begin begin
size := (size+sizeof(tmemchunk_fixed_hdr)+(blocksize-1)) and fixedsizemask; size := (size+(sizeof(tmemchunk_fixed_hdr)+(blocksize-1))) and fixedsizemask;
result := sysgetmem_fixed(size); result := sysgetmem_fixed(size);
end end
else else
begin begin
size := (size+sizeof(tmemchunk_var_hdr)+(blocksize-1)) and sizemask; size := (size+(sizeof(tmemchunk_var_hdr)+(blocksize-1))) and sizemask;
result := sysgetmem_var(size); result := sysgetmem_var(size);
end; end;
end; end;
@ -976,27 +977,29 @@ end;
function SysFreeMem_Fixed(pmc: pmemchunk_fixed): ptrint; function SysFreeMem_Fixed(pmc: pmemchunk_fixed): ptrint;
var var
hp : pmemchunk_fixed;
chunksize, chunksize,
chunkindex : ptrint; chunkindex : ptrint;
poc : poschunk; poc : poschunk;
begin begin
poc := pmc^.poc; poc := pmc^.poc;
chunkindex:=poc^.chunkindex;
chunksize:=chunkindex shl blockshift; chunksize:=chunkindex shl blockshift;
chunkindex:=poc^.chunkindex;
{ statistics } { statistics }
dec(internal_status.currheapused,chunksize); dec(internal_status.currheapused,chunksize);
hp:=freelists_fixed[chunkindex];
{ insert the block in it's freelist } { insert the block in it's freelist }
pmc^.prev_fixed := nil; pmc^.prev_fixed := nil;
pmc^.next_fixed := freelists_fixed[chunkindex]; pmc^.next_fixed := hp;
if freelists_fixed[chunkindex]<>nil then if assigned(hp) then
freelists_fixed[chunkindex]^.prev_fixed := pmc; hp^.prev_fixed := pmc;
freelists_fixed[chunkindex] := pmc; freelists_fixed[chunkindex] := pmc;
{ decrease used blocks count }
if poc^.used = 0 then
HandleError(204);
dec(poc^.used); dec(poc^.used);
if poc^.used = 0 then if poc^.used <= 0 then
begin begin
{ decrease used blocks count }
if poc^.used=-1 then
HandleError(204);
{ osblock can be freed? } { osblock can be freed? }
if freelists_free_chunk[chunkindex] then if freelists_free_chunk[chunkindex] then
append_to_oslist_fixed(poc) append_to_oslist_fixed(poc)
@ -1025,19 +1028,21 @@ end;
function SysFreeMem(p: pointer): ptrint; function SysFreeMem(p: pointer): ptrint;
var var
size : ptrint; hp : pmemchunk_fixed;
begin begin
if p=nil then if p=nil then
begin begin
result:=0; result:=0;
exit; exit;
end; end;
size := pmemchunk_fixed(p-sizeof(tmemchunk_fixed_hdr))^.size;
hp:=pmemchunk_fixed(p-sizeof(tmemchunk_fixed_hdr));
{ check if this is a fixed- or var-sized chunk } { check if this is a fixed- or var-sized chunk }
if (size and fixedsizeflag) = 0 then if (hp^.size and fixedsizeflag) = 0 then
result := sysfreemem_var(pmemchunk_var(p-sizeof(tmemchunk_var_hdr))) result := sysfreemem_var(pmemchunk_var(p-sizeof(tmemchunk_var_hdr)))
else else
result := sysfreemem_fixed(pmemchunk_fixed(p-sizeof(tmemchunk_fixed_hdr))); result := sysfreemem_fixed(hp);
end; end;
{***************************************************************************** {*****************************************************************************
@ -1046,7 +1051,7 @@ end;
Function SysFreeMemSize(p: pointer; size: ptrint):ptrint; Function SysFreeMemSize(p: pointer; size: ptrint):ptrint;
var var
chunksize: ptrint; hp : pmemchunk_fixed;
begin begin
SysFreeMemSize := 0; SysFreeMemSize := 0;
if p=nil then if p=nil then
@ -1058,14 +1063,14 @@ begin
exit; exit;
end; end;
chunksize := pmemchunk_fixed(p-sizeof(tmemchunk_fixed_hdr))^.size; hp:=pmemchunk_fixed(p-sizeof(tmemchunk_fixed_hdr));
{ check if this is a fixed- or var-sized chunk. We can't check the passed { check if this is a fixed- or var-sized chunk. We can't check the passed
size parameter since the block can be resized (by reallocmem) to an size parameter since the block can be resized (by reallocmem) to an
optimized value that the user doesn't know } optimized value that the user doesn't know }
if (chunksize and fixedsizeflag) = 0 then if (hp^.size and fixedsizeflag) = 0 then
result := sysfreemem_var(pmemchunk_var(p-sizeof(tmemchunk_var_hdr))) result := sysfreemem_var(pmemchunk_var(p-sizeof(tmemchunk_var_hdr)))
else else
result := sysfreemem_fixed(pmemchunk_fixed(p-sizeof(tmemchunk_fixed_hdr))); result := sysfreemem_fixed(hp);
end; end;