Explorar o código

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

sergei %!s(int64=14) %!d(string=hai) anos
pai
achega
f2852137c8
Modificáronse 3 ficheiros con 22 adicións e 59 borrados
  1. 8 21
      rtl/inc/astrings.inc
  2. 8 21
      rtl/inc/ustrings.inc
  3. 6 17
      rtl/inc/wstrings.inc

+ 8 - 21
rtl/inc/astrings.inc

@@ -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}

+ 8 - 21
rtl/inc/ustrings.inc

@@ -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 }

+ 6 - 17
rtl/inc/wstrings.inc

@@ -154,37 +154,26 @@ begin
 end;
 
 
-Procedure DisposeWideString(Var S : Pointer);
+Procedure fpc_WideStr_Decr_Ref (Var S : Pointer);[Public,Alias:'FPC_WIDESTR_DECR_REF']; compilerproc;
 {
-  Deallocates a WideString From the heap.
+  Decreases the ReferenceCount of a non constant widestring;
+  If the reference count is zero, deallocate the string;
 }
-begin
+Begin
   If S=Nil then
     exit;
-{$ifndef MSWINDOWS}
-  Dec (S,WideFirstOff);
-  Freemem(S);
-{$else MSWINDOWS}
+{$ifdef MSWINDOWS}
   if winwidestringalloc then
     SysFreeString(S)
   else
+{$endif MSWINDOWS}
     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 }
-end;
-
 { alias for internal use }
 Procedure fpc_WideStr_Decr_Ref (Var S : Pointer);[external name 'FPC_WIDESTR_DECR_REF'];