use a hashmap to retrieve the IDE services

This commit is contained in:
Basile Burg 2018-04-26 15:36:36 +02:00
parent d9dd7ad6fa
commit a6b630f090
1 changed files with 7 additions and 14 deletions

View File

@ -5,7 +5,7 @@ unit ce_observer;
interface interface
uses uses
Classes, SysUtils, Contnrs; Classes, SysUtils, Contnrs, ce_common;
type type
@ -19,8 +19,7 @@ type
function singleServiceName: string; function singleServiceName: string;
end; end;
//TServiceList = class(specialize TStringHashMap<TObject>) TServiceList = class(specialize TStringHashMap<TObject>);
//end;
(** (**
* Manages the connections between the observers and their subjects in the * Manages the connections between the observers and their subjects in the
@ -30,7 +29,7 @@ type
private private
fObservers: TObjectList; fObservers: TObjectList;
fSubjects: TObjectList; fSubjects: TObjectList;
fServices: TObjectList; fServices: TServiceList;
fUpdatesCount: Integer; fUpdatesCount: Integer;
procedure tryUpdate; procedure tryUpdate;
procedure updateEntities; procedure updateEntities;
@ -110,7 +109,7 @@ constructor TCEEntitiesConnector.Create;
begin begin
fObservers := TObjectList.Create(False); fObservers := TObjectList.Create(False);
fSubjects := TObjectList.Create(False); fSubjects := TObjectList.Create(False);
fServices := TObjectList.Create(False); fServices := TServiceList.Create();
end; end;
destructor TCEEntitiesConnector.Destroy; destructor TCEEntitiesConnector.Destroy;
@ -203,11 +202,9 @@ end;
procedure TCEEntitiesConnector.addSingleService(provider: TObject); procedure TCEEntitiesConnector.addSingleService(provider: TObject);
begin begin
if fServices.IndexOf(provider) <> -1 then
exit;
if not (provider is ICESingleService) then if not (provider is ICESingleService) then
exit; exit;
fServices.Add(provider); fServices.insert((provider as ICESingleService).singleServiceName, provider);
end; end;
function TCEEntitiesConnector.getSingleService(const serviceName: string): TObject; function TCEEntitiesConnector.getSingleService(const serviceName: string): TObject;
@ -216,12 +213,8 @@ var
serv: ICESingleService; serv: ICESingleService;
begin begin
Result := nil; Result := nil;
for i := 0 to fServices.Count - 1 do if not fServices.GetValue(serviceName, result) then
begin result := nil;
serv := fServices[i] as ICESingleService;
if serv.singleServiceName = serviceName then
exit(fServices[i]);
end;
end; end;
{$ENDREGION} {$ENDREGION}