|
@@ -152,6 +152,7 @@ type
|
|
TList<T> = class(TCustomList<T>)
|
|
TList<T> = class(TCustomList<T>)
|
|
private
|
|
private
|
|
FComparer: IComparer<T>;
|
|
FComparer: IComparer<T>;
|
|
|
|
+ function SameValue(const Left, Right: T): Boolean;
|
|
protected
|
|
protected
|
|
procedure SetCapacity(AValue: SizeInt); override;
|
|
procedure SetCapacity(AValue: SizeInt); override;
|
|
procedure SetCount(AValue: SizeInt);
|
|
procedure SetCount(AValue: SizeInt);
|
|
@@ -812,6 +813,14 @@ end;
|
|
|
|
|
|
{ TList }
|
|
{ TList }
|
|
|
|
|
|
|
|
+function TList<T>.SameValue(const Left, Right: T): Boolean;
|
|
|
|
+begin
|
|
|
|
+ if Assigned(FComparer) then
|
|
|
|
+ Result:=(FComparer.Compare(Left, Right) = 0)
|
|
|
|
+ else
|
|
|
|
+ Result:=(Left = Right);
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TList<T>.SetCapacity(AValue: SizeInt);
|
|
procedure TList<T>.SetCapacity(AValue: SizeInt);
|
|
begin
|
|
begin
|
|
if AValue < Count then
|
|
if AValue < Count then
|
|
@@ -877,7 +886,6 @@ end;
|
|
constructor TList<T>.Create;
|
|
constructor TList<T>.Create;
|
|
begin
|
|
begin
|
|
InitializeList;
|
|
InitializeList;
|
|
- FComparer := TComparer<T>.Default;
|
|
|
|
end;
|
|
end;
|
|
|
|
|
|
constructor TList<T>.Create(const AComparer: IComparer<T>);
|
|
constructor TList<T>.Create(const AComparer: IComparer<T>);
|
|
@@ -1111,7 +1119,7 @@ var
|
|
i: SizeInt;
|
|
i: SizeInt;
|
|
begin
|
|
begin
|
|
for i := 0 to Count - 1 do
|
|
for i := 0 to Count - 1 do
|
|
- if FComparer.Compare(AValue, FItems[i]) = 0 then
|
|
|
|
|
|
+ if SameValue(AValue, FItems[i]) then
|
|
Exit(i);
|
|
Exit(i);
|
|
Result:=-1;
|
|
Result:=-1;
|
|
end;
|
|
end;
|
|
@@ -1121,7 +1129,7 @@ var
|
|
i: SizeInt;
|
|
i: SizeInt;
|
|
begin
|
|
begin
|
|
for i := Count - 1 downto 0 do
|
|
for i := Count - 1 downto 0 do
|
|
- if FComparer.Compare(AValue, FItems[i]) = 0 then
|
|
|
|
|
|
+ if SameValue(AValue, FItems[i]) then
|
|
Exit(i);
|
|
Exit(i);
|
|
Result:=-1;
|
|
Result:=-1;
|
|
end;
|
|
end;
|