Ignore:
Timestamp:
Mar 24, 2011, 6:50:50 AM (14 years ago)
Author:
george
Message:
  • Modified: Optimized TGList.IndexOf.
  • Used better compiler optimization level 3 for library.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Generics/TemplateGenerics/Generic/GenericList.inc

    r175 r219  
    2525    procedure QuickSort(L, R : TGListIndex; Compare: TGListSortCompare);
    2626  public
     27    function CompareMem(P1, P2: Pointer; Length: cardinal): Boolean; inline;
    2728    function Add(Item: TGListItem): TGListIndex;
    2829    procedure AddArray(Values: array of TGListItem);
     
    208209end;
    209210
     211function TGList.CompareMem(P1, P2: Pointer; Length: cardinal): Boolean;
     212var
     213  I: Cardinal;
     214begin
     215  Result := True;
     216  I := 0;
     217  if (P1) <> (P2) then
     218    while Result and (I < Length) do
     219    begin
     220      Result := PByte(P1)^ = PByte(P2)^;
     221      Inc(I);
     222      Inc(pchar(P1));
     223      Inc(pchar(P2));
     224    end;
     225end;
     226
    210227function TGList.IndexOf(Item: TGListItem; Start: TGListIndex): TGListIndex;
    211228begin
    212229  Result := Start;
    213230  while (Result < FCount) and
    214   not CompareMem(Addr(FItems[Result]), Addr(Item), SizeOf(TGListItem)) do
     231  not CompareMem(@FItems[Result], @Item, SizeOf(TGListItem)) do
     232//  not (CompareByte(FItems[Result], Item, SizeOf(TGListItem)) = 0) do
    215233    Result := Result + 1;
    216234  if Result = FCount then Result := -1;
Note: See TracChangeset for help on using the changeset viewer.