C99bb2b0dfcf7dba9aabf244a3330ac2

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?

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 !

Avatar

Kenny

September 24, 2009, September 24, 2009 21:15, permalink

No rating. Login to rate!

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;
C99bb2b0dfcf7dba9aabf244a3330ac2

DarkAxi0m

September 25, 2009, September 25, 2009 03:50, permalink

No rating. Login to rate!

Sorry i should have made it more clear about the function, i will update the first post.

Your refactoring





Format Copy from initial code

or Cancel