 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Cesar Romero Guest
|
Posted: Sun Sep 10, 2006 7:04 pm Post subject: Speed: How to fast find in Named InterfacedList |
|
|
I need to improve the access to objet members by name, I wrote my own,
but I dont few that this implementations is OK...
Can someone suggest a better way to do that or improve this?
Now Im using:
THashedInterfaceList = class(TInterfacedObject, IHashedInterfaceList)
private
FList: THashedStringList;
protected
function Add(const Name: string; const Item: IInterface): Integer;
function GetCount: Integer;
function GetItem(const Name: string): IInterface;
function GetItems(const Index: Integer): IInterface;
function IndexOf(const Name: string): Integer;
function IndexOfItem(const Item: IInterface): Integer;
procedure Clear;
procedure Delete(const Index: Integer);
property Item[const Name: string]: IInterface read GetItem;
property Items[const Index: Integer]: IInterface read GetItems;
default;
property Count: Integer read GetCount;
public
constructor Create(const SortList: boolean = False); virtual;
destructor Destroy; override;
end;
function THashedInterfaceList.Add(const Name: string;
const Item: IInterface): Integer;
begin
Result:= FList.AddObject(Name, Pointer(Item));
end;
procedure THashedInterfaceList.Clear;
begin
FList.Clear;
end;
constructor THashedInterfaceList.Create(const SortList: boolean);
begin
inherited Create;
FList:= THashedStringList.Create;
FList.Duplicates:= dupError;
FList.Sorted:= SortList;
end;
procedure THashedInterfaceList.Delete(const Index: Integer);
begin
FList.Delete(Index);
end;
destructor THashedInterfaceList.Destroy;
begin
FList.Free;
inherited;
end;
function THashedInterfaceList.GetCount: Integer;
begin
Result:= FList.Count;
end;
function THashedInterfaceList.GetItem(const Name: string): IInterface;
begin
Result:= Items[IndexOf(Name)];
end;
function THashedInterfaceList.GetItems(const Index: Integer):
IInterface;
var
LItem: Pointer;
begin
if (Index <> NotFound) and (Index < Count) then
LItem:= FList.Objects[Index]
else
LItem:= nil;
Result:= IInterface(LItem);
end;
function THashedInterfaceList.IndexOf(const Name: string): Integer;
begin
Result:= FList.IndexOf(Name);
end;
function THashedInterfaceList.IndexOfItem(const Item: IInterface):
Integer;
begin
Result:= FList.IndexOfObject(Pointer(Item));
end;
--
Cesar Romero
http://blogs.liws.com.br/cesar
http://www.liws.com.br/wiki |
|
| Back to top |
|
 |
Joao Morais Guest
|
Posted: Mon Sep 11, 2006 1:48 am Post subject: Re: Speed: How to fast find in Named InterfacedList |
|
|
Cesar Romero wrote:
| Quote: | I need to improve the access to objet members by name, I wrote my own,
but I dont few that this implementations is OK...
Can someone suggest a better way to do that or improve this?
|
About the improvement, it sounds as improved as possible. In order to
save some nanoseconds, you might call the IndexOf and the list getter
from inside the GetItem method.
About the approach, I'd use a pointer instead a string search. Faster
than the fastest searching algorithm, and it is not error prone. Just a
thought.
--
Joao Morais |
|
| Back to top |
|
 |
Cesar Romero Guest
|
Posted: Mon Sep 11, 2006 6:46 pm Post subject: Re: Speed: How to fast find in Named InterfacedList |
|
|
| Quote: | About the improvement, it sounds as improved as possible. In order to
save some nanoseconds, you might call the IndexOf and the list getter
from inside the GetItem method.
About the approach, I'd use a pointer instead a string search. Faster
than the fastest searching algorithm, and it is not error prone. Just
a thought.
|
Done with Lee Nover help
TNamedInterfaceList
Using TStringHash to hold the strings and now is very fast, Im using to
hold Members and Mapping in Jazz, that do a lot of Find(string).
Last version in http://jazz.liws.com.br/download/jazz_a5.zip
index.php/Alpha_5 look JazzClasses.pas unit.
Change log: http://www.liws.com.br/wiki/
[]s
Cesar Romero
http://blogs.liws.com.br/cesar
http://www.liws.com.br/wiki |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|