Skip to content

Commit

Permalink
Search from the back. #20
Browse files Browse the repository at this point in the history
  • Loading branch information
bero committed Dec 6, 2024
1 parent 836d7e0 commit f223554
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Source/BoldIndex.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit f223554

Please sign in to comment.