I have a record of arrays where i search and add new items and want to speed up things. removing ansicompare was a big step forward bit as much the count of records gets mor as slower the array gets. Thanks for any hints.

I have a record of arrays where i search and add new items and want to speed up things. removing ansicompare was a big step forward bit as much the count of records gets mor as slower the array gets. Thanks for any hints.

type
__params = record
vname:string;
vvalue:variant;
vdescription:string;
end;
c__params = tArray<__params>;

// I'm searching within the c__params array as follows:
function __tc_find(vData:c__params; vName:string):integer;
var
vmax, i:integer;
begin
result:=-1;
vname:=trim(lowercase(vname));

if vData<>nil then begin
vmax:=length(vData)-1;
for i:=0 to vmax do begin
// if ansisametext(vData[i].vname, vname) then begin ** very slow **
if (vData[i].vname=vname) then begin
result:=i;
break;
end;
end;
end;
end;

// and i'm adding new values with this
procedure __tc_add(var vparams:c__params; const vname:string; const vwert:variant; const vdescription:string='');
var
vmax, vfound:integer;
begin
vfound:=-1;
vmax:=length(vparams)-1;
vfound:=__tc_find(vparams, vname);

if vfound<>-1 then begin
vparams[vfound].vwert:=vwert;
if trim(vdescription)<>'' then vparams[vfound].vdescription:=vdescription;
end else begin
setlength(vparams, length(vparams)+1);
vmax:=length(vparams)-1;
vparams[vmax].vname:=trim(lowercase(vname));
vparams[vmax].vwert:=vwert;
vparams[vmax].vdescription:=vdescription;
end;
end;

Comments

  1. yusuf? did you try tlist? i will compare tdictionary and tlist to add and to search.

    ReplyDelete
  2. Emrah Kucukali i'm fine with tDictionary and tObjectDictionary. Its so fast i don't need anything else at the moment.

    ReplyDelete
  3. Emrah Kucukali you just repeated the question. TList is just a wrapper around an array.

    ReplyDelete

Post a Comment