Browse Source

* More efficient algorithm for reverse in case Self is passed. By BrunoK

Michaël Van Canneyt 3 weeks ago
parent
commit
bc4b38a526
1 changed files with 8 additions and 15 deletions
  1. 8 15
      rtl/objpas/classes/stringl.inc

+ 8 - 15
rtl/objpas/classes/stringl.inc

@@ -422,30 +422,23 @@ end;
 Procedure TStrings.Reverse(aList : TStrings);
 Procedure TStrings.Reverse(aList : TStrings);
 
 
 Var
 Var
-  I : Integer;
-  lList : TStrings;
-  lOwns : boolean;
+  I,J : Integer;
 
 
 begin
 begin
-  lOwns:=False;
   if aList=self then
   if aList=self then
     begin
     begin
-    lList:=Nil;
-    BeginUpdate;
+    I:=0; 
+    J:=Count-1;
+    beginUpdate;
     try
     try
-      if (self is TStringList) then
+      while I<J do 
         begin
         begin
-        lOwns:=TstringList(Self).OwnsObjects;
-        TStringList(Self).OwnsObjects:=False;
+        Exchange(I, J);
+        Inc(I);
+        Dec(J);
         end;
         end;
-      lList:=TStringList.Create;
-      Reverse(lList);
-      AddStrings(lList,True);
     finally
     finally
-      if (self is TStringList) then
-        TStringList(Self).OwnsObjects:=lOwns;
       EndUpdate;
       EndUpdate;
-      lList.Free;
     end;
     end;
     end
     end
   else 
   else