1 2 3 4 5 6 7 8
function indexOfValue(list : TStrings; value : string): integer; begin Result := 0; while (Result < list.Count) and (not SameText(list.ValueFromIndex[Result], value)) do Inc(Result); if Result >= list.Count then Result := -1; end;
Refactorings
No refactoring yet !
Kenny
September 24, 2009, September 24, 2009 21:15, permalink
The way you implemented this is identical to how TStrings.IndexOf handles it. Only your implementation has the overhead of additional function calls to look up TStrings.Count and TStrings.ValueFromIndex. Unless there are other characteristics to the TStrings list that haven't been mentioned (its sorted or only a specific subset of strings is allowed) you won't get better than Delphi's own implementation.
1 2 3 4
function indexOfValue(list : TStrings; value : string): integer; begin Result := list.IndexOf(value); end;
this function finds the first match in stringlist
where the value part of a "name=value" pair is equal value passed.
Any thoughts on speeding this up?