mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-14 10:20:21 +02:00
* DisposeAnsiString doesn't need to exist as a separate procedure, because it is only called from a single place. Merging it into caller yields somewhat more efficient code.
* DisposeWideString,DisposeUnicodeString: likewise. git-svn-id: trunk@19163 -
This commit is contained in:
parent
c73b6cfbd4
commit
f2852137c8
@ -78,40 +78,27 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
Procedure DisposeAnsiString(Var S : Pointer); {$IFNDEF VER2_0} Inline; {$ENDIF}
|
||||
{
|
||||
Deallocates a AnsiString From the heap.
|
||||
}
|
||||
begin
|
||||
If S=Nil then
|
||||
exit;
|
||||
Dec (S,AnsiFirstOff);
|
||||
FreeMem (S);
|
||||
S:=Nil;
|
||||
end;
|
||||
|
||||
{$ifndef FPC_SYSTEM_HAS_ANSISTR_DECR_REF}
|
||||
Procedure fpc_ansistr_decr_ref (Var S : Pointer); [Public,Alias:'FPC_ANSISTR_DECR_REF']; compilerproc;
|
||||
{
|
||||
Decreases the ReferenceCount of a non constant ansistring;
|
||||
If the reference count is zero, deallocate the string;
|
||||
}
|
||||
Type
|
||||
pSizeInt = ^SizeInt;
|
||||
Var
|
||||
l : pSizeInt;
|
||||
p: PAnsiRec;
|
||||
Begin
|
||||
{ Zero string }
|
||||
If S=Nil then
|
||||
exit;
|
||||
{ check for constant strings ...}
|
||||
l:=@PAnsiRec(S-AnsiFirstOff)^.Ref;
|
||||
If l^<0 then
|
||||
exit;
|
||||
p:=PAnsiRec(S-AnsiFirstOff);
|
||||
If p^.ref<0 then exit;
|
||||
{ declocked does a MT safe dec and returns true, if the counter is 0 }
|
||||
If declocked(l^) then
|
||||
{ Ref count dropped to zero }
|
||||
DisposeAnsiString (S); { Remove...}
|
||||
If declocked(p^.ref) then
|
||||
begin
|
||||
FreeMem(p);
|
||||
s:=nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
{$endif FPC_SYSTEM_HAS_ANSISTR_DECR_REF}
|
||||
|
@ -197,41 +197,28 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
Procedure DisposeUnicodeString(Var S : Pointer);
|
||||
{
|
||||
Deallocates a UnicodeString From the heap.
|
||||
}
|
||||
begin
|
||||
If S=Nil then
|
||||
exit;
|
||||
Dec (S,UnicodeFirstOff);
|
||||
Freemem(S);
|
||||
S:=Nil;
|
||||
end;
|
||||
|
||||
|
||||
Procedure fpc_UnicodeStr_Decr_Ref (Var S : Pointer);[Public,Alias:'FPC_UNICODESTR_DECR_REF']; compilerproc;
|
||||
{
|
||||
Decreases the ReferenceCount of a non constant unicodestring;
|
||||
If the reference count is zero, deallocate the string;
|
||||
}
|
||||
Type
|
||||
pSizeInt = ^SizeInt;
|
||||
Var
|
||||
l : pSizeInt;
|
||||
p: PUnicodeRec;
|
||||
Begin
|
||||
{ Zero string }
|
||||
if S=Nil then
|
||||
exit;
|
||||
{ check for constant strings ...}
|
||||
l:=@PUnicodeRec(S-UnicodeFirstOff)^.Ref;
|
||||
if l^<0 then
|
||||
p:=PUnicodeRec(S-UnicodeFirstOff);
|
||||
if p^.Ref<0 then
|
||||
exit;
|
||||
|
||||
{ declocked does a MT safe dec and returns true, if the counter is 0 }
|
||||
if declocked(l^) then
|
||||
{ Ref count dropped to zero remove }
|
||||
DisposeUnicodeString(S);
|
||||
if declocked(p^.Ref) then
|
||||
begin
|
||||
FreeMem(p);
|
||||
S:=nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ alias for internal use }
|
||||
|
@ -154,35 +154,24 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
Procedure DisposeWideString(Var S : Pointer);
|
||||
{
|
||||
Deallocates a WideString From the heap.
|
||||
}
|
||||
begin
|
||||
If S=Nil then
|
||||
exit;
|
||||
{$ifndef MSWINDOWS}
|
||||
Dec (S,WideFirstOff);
|
||||
Freemem(S);
|
||||
{$else MSWINDOWS}
|
||||
if winwidestringalloc then
|
||||
SysFreeString(S)
|
||||
else
|
||||
begin
|
||||
Dec (S,WideFirstOff);
|
||||
Freemem(S);
|
||||
end;
|
||||
{$endif MSWINDOWS}
|
||||
S:=Nil;
|
||||
end;
|
||||
|
||||
Procedure fpc_WideStr_Decr_Ref (Var S : Pointer);[Public,Alias:'FPC_WIDESTR_DECR_REF']; compilerproc;
|
||||
{
|
||||
Decreases the ReferenceCount of a non constant widestring;
|
||||
If the reference count is zero, deallocate the string;
|
||||
}
|
||||
Begin
|
||||
DisposeWideString(S); { does test for nil }
|
||||
If S=Nil then
|
||||
exit;
|
||||
{$ifdef MSWINDOWS}
|
||||
if winwidestringalloc then
|
||||
SysFreeString(S)
|
||||
else
|
||||
{$endif MSWINDOWS}
|
||||
begin
|
||||
Dec (S,WideFirstOff);
|
||||
Freemem(S);
|
||||
end;
|
||||
S:=Nil;
|
||||
end;
|
||||
|
||||
{ alias for internal use }
|
||||
|
Loading…
Reference in New Issue
Block a user