From 0fcd4927f4d6eb9a955a95e0b3fd742bfcb73d83 Mon Sep 17 00:00:00 2001 From: paul Date: Thu, 10 Dec 2009 08:35:47 +0000 Subject: [PATCH] lcl: fix search in StringHashList by Mattias Hansson (issue #0014551) git-svn-id: trunk@23061 - --- lcl/stringhashlist.pas | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lcl/stringhashlist.pas b/lcl/stringhashlist.pas index 37e734ef08..44671fdbbf 100644 --- a/lcl/stringhashlist.pas +++ b/lcl/stringhashlist.pas @@ -243,16 +243,18 @@ begin begin Result:= -1; First:= Temp -1; - if First > 0 then - while CompareValue(Value, FList[First]^.HashValue) = 0 do + //Find first matching hash index + while (First >= 0) and (CompareValue(Value, FList[First]^.HashValue) = 0) do dec(First); - inc(First); + if (First < 0) or ((CompareValue(Value, FList[First]^.HashValue) <> 0)) then + inc(First); + //Find the last matching hash index Last:= Temp +1; - if Last < Count -1 then - while CompareValue(Value, FList[Last]^.HashValue) = 0 do + while (Last <= (FCount - 1)) and (CompareValue(Value, FList[Last]^.HashValue) = 0) do inc(Last); - dec(Last); - for I:= First to Last do + if (Last > (FCount - 1)) or (CompareValue(Value, FList[Last]^.HashValue) <> 0) then + dec(Last); + for I := First to Last do if CompareString(S, FList[I]^.Key) then begin Result:= I;