Browse Source

--- Merging r34462 into '.':
U rtl/objpas/classes/lists.inc
--- Recording mergeinfo for merge of r34462 into '.':
U .
--- Merging r34861 into '.':
G rtl/objpas/classes/lists.inc
--- Recording mergeinfo for merge of r34861 into '.':
G .

# revisions: 34462,34861

git-svn-id: branches/fixes_3_0@36533 -

marco 8 years ago
parent
commit
a4ee31bd2f
1 changed files with 15 additions and 6 deletions
  1. 15 6
      rtl/objpas/classes/lists.inc

+ 15 - 6
rtl/objpas/classes/lists.inc

@@ -144,10 +144,12 @@ begin
     Error (SListIndexError, Index);
   FCount := FCount-1;
   System.Move (FList^[Index+1], FList^[Index], (FCount - Index) * SizeOf(Pointer));
-  // Shrink the list if appropriate
+  // Shrink the list if appropriate:
+  // If capacity>256 and the list is less than a quarter filled,  shrink to 1/2 the size.
+  // Shr is used because it is faster than div.
   if (FCapacity > 256) and (FCount < FCapacity shr 2) then
   begin
-    FCapacity := FCapacity shr 1;
+    FCapacity := FCapacity shr 1; 
     ReallocMem(FList, SizeOf(Pointer) * FCapacity);
   end;
 end;
@@ -175,10 +177,17 @@ var
   IncSize : Longint;
 begin
   if FCount < FCapacity then exit(self);
-  IncSize := 4;
-  if FCapacity > 3 then IncSize := IncSize + 4;
-  if FCapacity > 8 then IncSize := IncSize+8;
-  if FCapacity > 127 then Inc(IncSize, FCapacity shr 2);
+  {
+    For really big lists, (128Mb elements), increase with fixed amount: 16Mb elements (=1/8th of 128Mb).
+    For big lists (8mb elements), increase with 1/8th of the size
+    For moderate lists (128 or more, increase with 1/4th the size
+    For smaller sizes, increase with 16 or 4  
+  }
+  if FCapacity > 128*1024*1024 then IncSize := 16*1024*1024
+  else if FCapacity > 8*1024*1024 then IncSize := FCapacity shr 3
+  else if FCapacity > 128 then IncSize := FCapacity shr 2
+  else if FCapacity > 8 then IncSize := 16
+  else IncSize := 4; 
   SetCapacity(FCapacity + IncSize);
   Result := Self;
 end;