From f223554297003ab877352e1d7e002fb400ade1a5 Mon Sep 17 00:00:00 2001 From: Roland Bengtsson Date: Fri, 6 Dec 2024 23:40:57 +0200 Subject: [PATCH] Search from the back. #20 --- Source/BoldIndex.pas | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Source/BoldIndex.pas b/Source/BoldIndex.pas index d5e3955..3693cf3 100644 --- a/Source/BoldIndex.pas +++ b/Source/BoldIndex.pas @@ -815,11 +815,9 @@ procedure TBoldIntegerIndex.RangeError(Index: integer); function TBoldIntegerIndex.IndexOf(Item: TObject): integer; begin - Result := 0; - while (Result < FCount) and (FObjectStaticArray^[Result] <> Item) do - Inc(Result); - if Result = FCount then - Result := -1; + Result := FCount-1; + while (Result >= 0) and (FObjectStaticArray^[Result] <> Item) do + Dec(Result); end; function TBoldIntegerIndex.Includes(Item: TObject): boolean; @@ -841,14 +839,16 @@ function TBoldIntegerIndex.Remove(Item: TObject): boolean; var Index: Integer; begin - Index := IndexOf(Item); - if Index >= 0 then + result := false; + if FCount > 0 then begin - RemoveByIndex(Index); - result := true; - end - else - result := false; + Index := IndexOf(Item); + if Index >= 0 then + begin + RemoveByIndex(Index); + result := true; + end; + end; end; procedure TBoldIntegerIndex.RemoveChanged(Item: TObject);