Forum > FPC development

A propose for TStringList.Find...

(1/1)

edgarrod71:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function TStringList.Find(const S: string; out Index: Integer): Boolean; var  L, R, I: Integer;  CompareRes: PtrInt;begin  Result := false;  Index:=-1;  if Not Sorted then    Raise EListError.Create(SErrFindNeedsSortedList);  // Use binary search.  L := 0;  R := Pred(Count);  // Count - 1;  if L<=R then  //  while (L<=R) do  repeat    // repeat is 5-10% faster than while, so    I := L + (R - L) shr 1; // div 2;  shr is faster than div...    CompareRes := DoCompareText(S, Flist^[I].FString);    if (CompareRes>0) then      L := Succ(I); // I+1;  instead of adding, Succ or Pred only checks... so faster code.    else begin      R := Pred(I); // I-1;      if (CompareRes=0) then begin         Result := true;         if (Duplicates<>dupAccept) then            L := I; // forces end of while loop      end;    end;  until L>R;  Index := L;end;

marcov:
So where is the benchmark code to compare ?

RAW:
If the normal TStringlist is too slow, then it should be no problem at all to find a good HashList...
There are several improved TStringlists and several HashLists out there...

Just pick one and play trial and error...  :)

Navigation

[0] Message Index

Go to full version