indeed. What an improper place for THashedStringList
+1
At the moment I work with ValueListEditor. It uses a TStringlist-descendent named TValueListStrings which uses the TString.IndexOfName-method to derive the keynames and values.
even GetItemProp uses the TString.IndexOfName. Making the TValueListStrings a THashedStringList -descendent would be much better.
But then the unit ValEdit would be a descendent of inifiles what is not a good thing and hardly understandable.
I'd vote for an independent unit e.G: HashStrLst so that inifiles, valedit and any other component that needed this could descend from that.
[Edit]
Actually, it's probably the class name that's not quite accurate. THashedStringList is based on the TFPHashList. FPHashList has a limitation of using shortstring as look-up key. Using only 256 ansi characters string is totally fine for .ini files (unless .ini file is machine-generated for whatever crazy tasks), but on the wide scope, one might need to lookup for values that are more than 256 characters. Especially with UTF8 used for LCL.
Using only the first 256 character to generate the hash would only be a problem if you have lot of keynames that have the same start and only differ after the 256 character.
The only case i could think of that is if you want to hash the place of files in a full path, to give them some extra property. But in that case other components are much more appropriate.
In the normal-ini-file-case i see no need to change something.
@marcov:
I just looked in the Delphi-RTL, TStrings and TStringlist act quite like their Lazarus-siblings. TStrings does a linear search on both indexof and IndexOfName. TStringlist only does a binary-search in indexof via the find-method when the list is sorted.
So it's delphi-compatibility vs. better code. ( I go for the better code )
So sorry about the wrong info.
@marcodor:
I think you try something like:
// classesh.inc (Line 757 ff)
function IndexOf(const S: string): Integer; override;
function IndexOfName(const S: string): Integer; override; // <----
procedure Insert(Index: Integer; const S: string); override;
// stringl.inc (line 1336 ff new)
Function TStringList.IndexOfName(const S: string): Integer;
begin
If Not Sorted then
Result:=Inherited indexOfName(S)
else
// faster using binary search...
begin
Find (S,Result); // This should work since Find outputs the L-Value.
if (Result >= Count) or (Names[Result] <> S) then
Result:= -1;
end;
end;