Changeset 104 for trunk/UContact.pas


Ignore:
Timestamp:
Feb 9, 2022, 5:07:14 PM (3 years ago)
Author:
chronos
Message:
  • Modified: Updated speed of loading of big number of contacts.
  • Added: Contact field indexes cache for faster reverse search of contact fields by its index.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UContact.pas

    r103 r104  
    7171
    7272  TContactFields = class(TFPGObjectList<TContactField>)
     73  private
     74    Indexes: array[TContactFieldIndex] of TContactField;
     75    IndexesUpdated: Boolean;
     76  public
     77    procedure UpdateIndexes;
    7378    function AddNew(Name: string; Groups: array of string; NoGroups: array of string;
    7479      Title: string; Index: TContactFieldIndex; DataType:
     
    209214resourcestring
    210215  SVCardFile = 'vCard file';
     216  SFieldIndexRedefined = 'Field index %d redefined';
    211217  SExpectedVCardBegin = 'Expected vCard begin';
    212218  SFieldIndexNotDefined = 'Field index not defined';
     
    779785{ TContactFields }
    780786
     787procedure TContactFields.UpdateIndexes;
     788var
     789  I: Integer;
     790  Index: TContactFieldIndex;
     791begin
     792  for Index := Low(TContactFieldIndex) to High(TContactFieldIndex) do
     793    Indexes[Index] := nil;
     794  for I := 0 to Count - 1 do
     795    if not Assigned(Indexes[Items[I].Index]) then Indexes[Items[I].Index] := Items[I]
     796      else raise Exception.Create(Format(SFieldIndexRedefined, [Integer(Items[I].Index)]));
     797  IndexesUpdated := True;
     798end;
     799
    781800function TContactFields.AddNew(Name: string; Groups: array of string;
    782801  NoGroups: array of string; Title: string; Index: TContactFieldIndex;
     
    798817  Result.DataType := DataType;
    799818  Add(Result);
     819  IndexesUpdated := False;
    800820end;
    801821
     
    825845  I: Integer;
    826846begin
    827   I := 0;
    828   while (I < Count) and (Items[I].Index <> Index) do Inc(I);
    829   if I < Count then Result := Items[I]
    830     else Result := nil;
     847  if IndexesUpdated then Result := Indexes[Index]
     848  else begin
     849    I := 0;
     850    while (I < Count) and (Items[I].Index <> Index) do Inc(I);
     851    if I < Count then Result := Items[I]
     852      else Result := nil;
     853  end;
    831854end;
    832855
     
    958981    with AddNew('X-MYSPACE', [], [], SMySpace, cfMySpace, dtString) do
    959982      AddAlternative('X-SOCIALPROFILE', ['MYSPACE'], []);
     983    UpdateIndexes;
    960984    end;
    961985  end;
Note: See TracChangeset for help on using the changeset viewer.