Ignore:
Timestamp:
Oct 30, 2010, 6:39:12 PM (14 years ago)
Author:
george
Message:
  • Added: Ability of TListObject to own items and be able to free them on deletion and list destruction.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Generics/TemplateGenerics/Generic/ListImplementation.tpl

    r77 r78  
    1717begin
    1818  Result := FItems[Index];
    19 end;
    20 
    21 function TGList.GetCount: TListIndex;
    22 begin
    23   Result := FCount;
    2419end;
    2520
     
    8984end;
    9085
     86procedure TGList.Contract;
     87begin
     88  if (Capacity > 256) and (FCount < Capacity shr 2) then
     89  begin
     90    Capacity := Capacity shr 1;
     91  end;
     92end;
     93
    9194function TGList.Extract(Item: TListItem): TListItem;
    9295var
     
    344347  FCount := FCount - 1;
    345348  System.Move(FItems[Index + 1], FItems[Index], (FCount - Index) * SizeOf(TListItem));
    346   // Shrink the list if appropriate
    347   if (Capacity > 256) and (FCount < Capacity shr 2) then
    348   begin
    349     Capacity := Capacity shr 1;
    350   end;
     349  Contract;
    351350end;
    352351
Note: See TracChangeset for help on using the changeset viewer.