I think you are not using EnglishStringList (TStringList) correctly. This is a sorted list, you add elements (strings), sort them, but when you search, you do this with a partial string (only with the name IndexOfName ).
If you use IndexOfName in a sorted list, TStringList cannot use Dicotomic search. It uses sequential search.
(this is an implementation of IndexOfName)
for Result := 0 to GetCount - 1 do begin S := Get(Result); P := AnsiPos('=', S); if (P <> 0) and (CompareStrings(Copy(S, 1, P - 1), Name) = 0) then Exit; end;
I think this is the reason for poor performance.
An alternative is to use 2 TStringList:
* The first (sorted) contains only the "Name" and a pointer to the second list containing the value; You can implement this pointer to the second list using the "pointer" of the Object property.
* The second (unsorted) list contains values.
When you search, you do this in the first list; In this case, you can use the Find method. when you find a name, a pointer (implemented using the Object property) gives you a position in the second list with a value.
In this case, the search method in the Sorted List is more efficient for the HashList (which must execute the function in order to get the position of the value).
Sincerely.
Pd: Sorry about my mistakes with English.
Germán Estévez -Neftalí-
source share