* essentially undo 4823ca7114 as comparers that need now use a suitable class implementation directly

(cherry picked from commit 939f7345ac)
This commit is contained in:
Sven/Sarah Barth 2023-03-28 23:12:45 +02:00 committed by marcoonthegit
parent be7eec7f24
commit 7ae9a8745a

View File

@ -330,20 +330,19 @@ type
TComparerService = class abstract TComparerService = class abstract
private type private type
TSelectMethod = function(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer of object; TSelectMethod = function(ATypeData: PTypeData; ASize: SizeInt): Pointer of object;
private private
class function SelectIntegerEqualityComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; virtual; abstract; class function SelectIntegerEqualityComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; virtual; abstract;
class function SelectFloatEqualityComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; virtual; abstract; class function SelectFloatEqualityComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; virtual; abstract;
class function SelectShortStringEqualityComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; virtual; abstract; class function SelectShortStringEqualityComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; virtual; abstract;
class function SelectBinaryEqualityComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; virtual; abstract; class function SelectBinaryEqualityComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; virtual; abstract;
class function SelectDynArrayEqualityComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; virtual; abstract; class function SelectDynArrayEqualityComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; virtual; abstract;
private type private type
PSpoofInterfacedTypeSizeObject = ^TSpoofInterfacedTypeSizeObject; PSpoofInterfacedTypeSizeObject = ^TSpoofInterfacedTypeSizeObject;
TSpoofInterfacedTypeSizeObject = record TSpoofInterfacedTypeSizeObject = record
VMT: Pointer; VMT: Pointer;
RefCount: LongInt; RefCount: LongInt;
Size: SizeInt; Size: SizeInt;
ConstParaRef: Boolean;
end; end;
PInstance = ^TInstance; PInstance = ^TInstance;
@ -364,17 +363,17 @@ type
Compare: CodePointer; Compare: CodePointer;
end; end;
TSelectFunc = function(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; TSelectFunc = function(ATypeData: PTypeData; ASize: SizeInt): Pointer;
private private
class function CreateInterface(AVMT: Pointer; ASize: SizeInt; AConstParaRef: Boolean): PSpoofInterfacedTypeSizeObject; static; class function CreateInterface(AVMT: Pointer; ASize: SizeInt): PSpoofInterfacedTypeSizeObject; static;
class function SelectIntegerComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; static; class function SelectIntegerComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; static;
class function SelectInt64Comparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; static; class function SelectInt64Comparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; static;
class function SelectFloatComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; static; class function SelectFloatComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; static;
class function SelectShortStringComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; static; class function SelectShortStringComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; static;
class function SelectBinaryComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; static; class function SelectBinaryComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; static;
class function SelectDynArrayComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; static; class function SelectDynArrayComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; static;
private const private const
UseBinaryMethods: set of TTypeKind = [tkUnknown, tkSet, tkFile, tkArray, tkRecord, tkObject]; UseBinaryMethods: set of TTypeKind = [tkUnknown, tkSet, tkFile, tkArray, tkRecord, tkObject];
@ -506,18 +505,18 @@ type
(Selector: False; Instance: @Comparer_Pointer_Instance) (Selector: False; Instance: @Comparer_Pointer_Instance)
); );
public public
class function LookupComparer(ATypeInfo: PTypeInfo; ASize: SizeInt; AConstParaRef: Boolean): Pointer; static; class function LookupComparer(ATypeInfo: PTypeInfo; ASize: SizeInt): Pointer; static;
end; end;
THashService = class(TComparerService) THashService = class(TComparerService)
public public
class function LookupEqualityComparer(ATypeInfo: PTypeInfo; ASize: SizeInt; AConstParaRef: Boolean): Pointer; virtual; abstract; class function LookupEqualityComparer(ATypeInfo: PTypeInfo; ASize: SizeInt): Pointer; virtual; abstract;
end; end;
TExtendedHashService = class(THashService) TExtendedHashService = class(THashService)
public public
class function LookupEqualityComparer(ATypeInfo: PTypeInfo; ASize: SizeInt; AConstParaRef: Boolean): Pointer; override; class function LookupEqualityComparer(ATypeInfo: PTypeInfo; ASize: SizeInt): Pointer; override;
class function LookupExtendedEqualityComparer(ATypeInfo: PTypeInfo; ASize: SizeInt; AConstParaRef: Boolean): Pointer; virtual; abstract; class function LookupExtendedEqualityComparer(ATypeInfo: PTypeInfo; ASize: SizeInt): Pointer; virtual; abstract;
end; end;
{$DEFINE HASH_FACTORY := PPEqualityComparerVMT(Self)^.__ClassRef} {$DEFINE HASH_FACTORY := PPEqualityComparerVMT(Self)^.__ClassRef}
@ -527,11 +526,11 @@ type
THashService<T: THashFactory> = class(THashService) THashService<T: THashFactory> = class(THashService)
private private
class function SelectIntegerEqualityComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; override; class function SelectIntegerEqualityComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; override;
class function SelectFloatEqualityComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; override; class function SelectFloatEqualityComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; override;
class function SelectShortStringEqualityComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; override; class function SelectShortStringEqualityComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; override;
class function SelectBinaryEqualityComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; override; class function SelectBinaryEqualityComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; override;
class function SelectDynArrayEqualityComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; override; class function SelectDynArrayEqualityComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; override;
private const private const
// IEqualityComparer VMT templates // IEqualityComparer VMT templates
{$WARNINGS OFF} {$WARNINGS OFF}
@ -639,18 +638,18 @@ type
private private
class constructor Create; class constructor Create;
public public
class function LookupEqualityComparer(ATypeInfo: PTypeInfo; ASize: SizeInt; AConstParaRef: Boolean): Pointer; override; class function LookupEqualityComparer(ATypeInfo: PTypeInfo; ASize: SizeInt): Pointer; override;
end; end;
{ TExtendedHashService } { TExtendedHashService }
TExtendedHashService<T: TExtendedHashFactory> = class(TExtendedHashService) TExtendedHashService<T: TExtendedHashFactory> = class(TExtendedHashService)
private private
class function SelectIntegerEqualityComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; override; class function SelectIntegerEqualityComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; override;
class function SelectFloatEqualityComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; override; class function SelectFloatEqualityComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; override;
class function SelectShortStringEqualityComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; override; class function SelectShortStringEqualityComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; override;
class function SelectBinaryEqualityComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; override; class function SelectBinaryEqualityComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; override;
class function SelectDynArrayEqualityComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; override; class function SelectDynArrayEqualityComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer; override;
private const private const
// IExtendedEqualityComparer VMT templates // IExtendedEqualityComparer VMT templates
{$WARNINGS OFF} {$WARNINGS OFF}
@ -758,7 +757,7 @@ type
private private
class constructor Create; class constructor Create;
public public
class function LookupExtendedEqualityComparer(ATypeInfo: PTypeInfo; ASize: SizeInt; AConstParaRef: Boolean): Pointer; override; class function LookupExtendedEqualityComparer(ATypeInfo: PTypeInfo; ASize: SizeInt): Pointer; override;
end; end;
TOnEqualityComparison<T> = function(const ALeft, ARight: T): Boolean of object; TOnEqualityComparison<T> = function(const ALeft, ARight: T): Boolean of object;
@ -1063,10 +1062,9 @@ type
function BobJenkinsHash(const AData; ALength, AInitData: Integer): Integer; // same result as HashLittle_Delphi, just different interface function BobJenkinsHash(const AData; ALength, AInitData: Integer): Integer; // same result as HashLittle_Delphi, just different interface
function BinaryCompare(const ALeft, ARight: Pointer; ASize: PtrUInt): Integer; inline; function BinaryCompare(const ALeft, ARight: Pointer; ASize: PtrUInt): Integer; inline;
function _LookupVtableInfo(AGInterface: TDefaultGenericInterface; ATypeInfo: PTypeInfo; ASize: SizeInt; function _LookupVtableInfo(AGInterface: TDefaultGenericInterface; ATypeInfo: PTypeInfo; ASize: SizeInt): Pointer; inline;
AConstParaRef: Boolean): Pointer; inline;
function _LookupVtableInfoEx(AGInterface: TDefaultGenericInterface; ATypeInfo: PTypeInfo; ASize: SizeInt; function _LookupVtableInfoEx(AGInterface: TDefaultGenericInterface; ATypeInfo: PTypeInfo; ASize: SizeInt;
AConstParaRef: Boolean; AFactory: THashFactoryClass): Pointer; AFactory: THashFactoryClass): Pointer;
implementation implementation
@ -1077,7 +1075,7 @@ begin
if GetTypeKind(T) in TComparerService.UseBinaryMethods then begin if GetTypeKind(T) in TComparerService.UseBinaryMethods then begin
Result := TBinaryComparer<T>.Create Result := TBinaryComparer<T>.Create
end else end else
Result := _LookupVtableInfo(giComparer, TypeInfo(T), SizeOf(T), ConstParamIsRef<T>()); Result := _LookupVtableInfo(giComparer, TypeInfo(T), SizeOf(T));
end; end;
class function TComparer<T>.Construct(const AComparison: TOnComparison<T>): IComparer<T>; class function TComparer<T>.Construct(const AComparison: TOnComparison<T>): IComparer<T>;
@ -1298,10 +1296,7 @@ class function TCompare._Binary(const ALeft, ARight): Integer;
var var
_self: TComparerService.PSpoofInterfacedTypeSizeObject absolute Self; _self: TComparerService.PSpoofInterfacedTypeSizeObject absolute Self;
begin begin
if _self.ConstParaRef then Result := CompareMemRange(@ALeft, @ARight, _self.Size)
Result := CompareMemRange(@ALeft, @ARight, _self.Size)
else
Result := CompareMemRange(PPointer(@ALeft)^, PPointer(@ARight)^, _self.Size);
end; end;
class function TCompare._DynArray(const ALeft, ARight: Pointer): Integer; class function TCompare._DynArray(const ALeft, ARight: Pointer): Integer;
@ -1560,10 +1555,7 @@ class function TEquals._Binary(const ALeft, ARight): Boolean;
var var
_self: TComparerService.PSpoofInterfacedTypeSizeObject absolute Self; _self: TComparerService.PSpoofInterfacedTypeSizeObject absolute Self;
begin begin
if _self.ConstParaRef then Result := CompareMem(@ALeft, @ARight, _self.Size)
Result := CompareMem(@ALeft, @ARight, _self.Size)
else
Result := CompareMem(PPointer(@ALeft)^, PPointer(@ARight)^, _self.Size);
end; end;
class function TEquals._DynArray(const ALeft, ARight: Pointer): Boolean; class function TEquals._DynArray(const ALeft, ARight: Pointer): Boolean;
@ -2104,16 +2096,15 @@ end;
{ TComparerService } { TComparerService }
class function TComparerService.CreateInterface(AVMT: Pointer; ASize: SizeInt; AConstParaRef: Boolean): PSpoofInterfacedTypeSizeObject; class function TComparerService.CreateInterface(AVMT: Pointer; ASize: SizeInt): PSpoofInterfacedTypeSizeObject;
begin begin
Result := New(PSpoofInterfacedTypeSizeObject); Result := New(PSpoofInterfacedTypeSizeObject);
Result.VMT := AVMT; Result.VMT := AVMT;
Result.RefCount := 0; Result.RefCount := 0;
Result.Size := ASize; Result.Size := ASize;
Result.ConstParaRef := AConstParaRef;
end; end;
class function TComparerService.SelectIntegerComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; class function TComparerService.SelectIntegerComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer;
begin begin
case ATypeData.OrdType of case ATypeData.OrdType of
otSByte: otSByte:
@ -2134,7 +2125,7 @@ begin
end; end;
end; end;
class function TComparerService.SelectInt64Comparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; class function TComparerService.SelectInt64Comparer(ATypeData: PTypeData; ASize: SizeInt): Pointer;
begin begin
if ATypeData.MaxInt64Value > ATypeData.MinInt64Value then if ATypeData.MaxInt64Value > ATypeData.MinInt64Value then
Exit(@Comparer_Int64_Instance) Exit(@Comparer_Int64_Instance)
@ -2143,7 +2134,7 @@ begin
end; end;
class function TComparerService.SelectFloatComparer(ATypeData: PTypeData; class function TComparerService.SelectFloatComparer(ATypeData: PTypeData;
ASize: SizeInt; AConstParaRef: Boolean): Pointer; ASize: SizeInt): Pointer;
begin begin
case ATypeData.FloatType of case ATypeData.FloatType of
ftSingle: ftSingle:
@ -2163,7 +2154,7 @@ begin
end; end;
class function TComparerService.SelectShortStringComparer(ATypeData: PTypeData; class function TComparerService.SelectShortStringComparer(ATypeData: PTypeData;
ASize: SizeInt; AConstParaRef: Boolean): Pointer; ASize: SizeInt): Pointer;
begin begin
case ASize of case ASize of
2: Exit(@Comparer_ShortString1_Instance); 2: Exit(@Comparer_ShortString1_Instance);
@ -2175,27 +2166,27 @@ begin
end; end;
class function TComparerService.SelectBinaryComparer(ATypeData: PTypeData; class function TComparerService.SelectBinaryComparer(ATypeData: PTypeData;
ASize: SizeInt; AConstParaRef: Boolean): Pointer; ASize: SizeInt): Pointer;
begin begin
Result := CreateInterface(@Comparer_Binary_VMT, ASize, AConstParaRef); Result := CreateInterface(@Comparer_Binary_VMT, ASize);
end; end;
class function TComparerService.SelectDynArrayComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; class function TComparerService.SelectDynArrayComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer;
begin begin
Result := CreateInterface(@Comparer_DynArray_VMT, ATypeData.elSize, AConstParaRef); Result := CreateInterface(@Comparer_DynArray_VMT, ATypeData.elSize);
end; end;
class function TComparerService.LookupComparer(ATypeInfo: PTypeInfo; ASize: SizeInt; AConstParaRef: Boolean): Pointer; class function TComparerService.LookupComparer(ATypeInfo: PTypeInfo; ASize: SizeInt): Pointer;
var var
LInstance: PInstance; LInstance: PInstance;
begin begin
if ATypeInfo = nil then if ATypeInfo = nil then
Exit(SelectBinaryComparer(Nil, ASize, AConstParaRef)) Exit(SelectBinaryComparer(Nil, ASize))
else else
begin begin
LInstance := @ComparerInstances[ATypeInfo.Kind]; LInstance := @ComparerInstances[ATypeInfo.Kind];
if LInstance.Selector then if LInstance.Selector then
Result := TSelectFunc(LInstance.SelectorInstance)(GetTypeData(ATypeInfo), ASize, AConstParaRef) Result := TSelectFunc(LInstance.SelectorInstance)(GetTypeData(ATypeInfo), ASize)
else else
Result := LInstance.Instance; Result := LInstance.Instance;
end; end;
@ -2218,14 +2209,14 @@ end;
{ TExtendedHashService } { TExtendedHashService }
class function TExtendedHashService.LookupEqualityComparer(ATypeInfo: PTypeInfo; ASize: SizeInt; AConstParaRef: Boolean): Pointer; class function TExtendedHashService.LookupEqualityComparer(ATypeInfo: PTypeInfo; ASize: SizeInt): Pointer;
begin begin
Result := LookupExtendedEqualityComparer(ATypeInfo, ASize, AConstParaRef); Result := LookupExtendedEqualityComparer(ATypeInfo, ASize);
end; end;
{ THashService } { THashService }
class function THashService<T>.SelectIntegerEqualityComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; class function THashService<T>.SelectIntegerEqualityComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer;
begin begin
case ATypeData.OrdType of case ATypeData.OrdType of
otSByte: otSByte:
@ -2247,7 +2238,7 @@ begin
end; end;
class function THashService<T>.SelectFloatEqualityComparer(ATypeData: PTypeData; class function THashService<T>.SelectFloatEqualityComparer(ATypeData: PTypeData;
ASize: SizeInt; AConstParaRef: Boolean): Pointer; ASize: SizeInt): Pointer;
begin begin
case ATypeData.FloatType of case ATypeData.FloatType of
ftSingle: ftSingle:
@ -2267,7 +2258,7 @@ begin
end; end;
class function THashService<T>.SelectShortStringEqualityComparer( class function THashService<T>.SelectShortStringEqualityComparer(
ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; ATypeData: PTypeData; ASize: SizeInt): Pointer;
begin begin
case ASize of case ASize of
2: Exit(@FEqualityComparer_ShortString1_Instance); 2: Exit(@FEqualityComparer_ShortString1_Instance);
@ -2279,25 +2270,25 @@ begin
end; end;
class function THashService<T>.SelectBinaryEqualityComparer(ATypeData: PTypeData; class function THashService<T>.SelectBinaryEqualityComparer(ATypeData: PTypeData;
ASize: SizeInt; AConstParaRef: Boolean): Pointer; ASize: SizeInt): Pointer;
begin begin
Result := CreateInterface(@FEqualityComparer_Binary_VMT, ASize, AConstParaRef); Result := CreateInterface(@FEqualityComparer_Binary_VMT, ASize);
end; end;
class function THashService<T>.SelectDynArrayEqualityComparer( class function THashService<T>.SelectDynArrayEqualityComparer(
ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; ATypeData: PTypeData; ASize: SizeInt): Pointer;
begin begin
Result := CreateInterface(@FEqualityComparer_DynArray_VMT, ATypeData.elSize, AConstParaRef); Result := CreateInterface(@FEqualityComparer_DynArray_VMT, ATypeData.elSize);
end; end;
class function THashService<T>.LookupEqualityComparer(ATypeInfo: PTypeInfo; class function THashService<T>.LookupEqualityComparer(ATypeInfo: PTypeInfo;
ASize: SizeInt; AConstParaRef: Boolean): Pointer; ASize: SizeInt): Pointer;
var var
LInstance: PInstance; LInstance: PInstance;
LSelectMethod: TSelectMethod; LSelectMethod: TSelectMethod;
begin begin
if ATypeInfo = nil then if ATypeInfo = nil then
Exit(SelectBinaryEqualityComparer(Nil, ASize, AConstParaRef)) Exit(SelectBinaryEqualityComparer(Nil, ASize))
else else
begin begin
LInstance := @FEqualityComparerInstances[ATypeInfo.Kind]; LInstance := @FEqualityComparerInstances[ATypeInfo.Kind];
@ -2306,7 +2297,7 @@ begin
begin begin
TMethod(LSelectMethod).Code := LInstance.SelectorInstance; TMethod(LSelectMethod).Code := LInstance.SelectorInstance;
TMethod(LSelectMethod).Data := Self; TMethod(LSelectMethod).Data := Self;
Result := LSelectMethod(GetTypeData(ATypeInfo), ASize, AConstParaRef); Result := LSelectMethod(GetTypeData(ATypeInfo), ASize);
end; end;
end; end;
end; end;
@ -2430,7 +2421,7 @@ end;
{ TExtendedHashService } { TExtendedHashService }
class function TExtendedHashService<T>.SelectIntegerEqualityComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; class function TExtendedHashService<T>.SelectIntegerEqualityComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer;
begin begin
case ATypeData.OrdType of case ATypeData.OrdType of
otSByte: otSByte:
@ -2451,7 +2442,7 @@ begin
end; end;
end; end;
class function TExtendedHashService<T>.SelectFloatEqualityComparer(ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; class function TExtendedHashService<T>.SelectFloatEqualityComparer(ATypeData: PTypeData; ASize: SizeInt): Pointer;
begin begin
case ATypeData.FloatType of case ATypeData.FloatType of
ftSingle: ftSingle:
@ -2471,7 +2462,7 @@ begin
end; end;
class function TExtendedHashService<T>.SelectShortStringEqualityComparer(ATypeData: PTypeData; class function TExtendedHashService<T>.SelectShortStringEqualityComparer(ATypeData: PTypeData;
ASize: SizeInt; AConstParaRef: Boolean): Pointer; ASize: SizeInt): Pointer;
begin begin
case ASize of case ASize of
2: Exit(@FExtendedEqualityComparer_ShortString1_Instance); 2: Exit(@FExtendedEqualityComparer_ShortString1_Instance);
@ -2483,25 +2474,25 @@ begin
end; end;
class function TExtendedHashService<T>.SelectBinaryEqualityComparer(ATypeData: PTypeData; class function TExtendedHashService<T>.SelectBinaryEqualityComparer(ATypeData: PTypeData;
ASize: SizeInt; AConstParaRef: Boolean): Pointer; ASize: SizeInt): Pointer;
begin begin
Result := CreateInterface(@FExtendedEqualityComparer_Binary_VMT, ASize, AConstParaRef); Result := CreateInterface(@FExtendedEqualityComparer_Binary_VMT, ASize);
end; end;
class function TExtendedHashService<T>.SelectDynArrayEqualityComparer( class function TExtendedHashService<T>.SelectDynArrayEqualityComparer(
ATypeData: PTypeData; ASize: SizeInt; AConstParaRef: Boolean): Pointer; ATypeData: PTypeData; ASize: SizeInt): Pointer;
begin begin
Result := CreateInterface(@FExtendedEqualityComparer_DynArray_VMT, ATypeData.elSize, AConstParaRef); Result := CreateInterface(@FExtendedEqualityComparer_DynArray_VMT, ATypeData.elSize);
end; end;
class function TExtendedHashService<T>.LookupExtendedEqualityComparer( class function TExtendedHashService<T>.LookupExtendedEqualityComparer(
ATypeInfo: PTypeInfo; ASize: SizeInt; AConstParaRef: Boolean): Pointer; ATypeInfo: PTypeInfo; ASize: SizeInt): Pointer;
var var
LInstance: PInstance; LInstance: PInstance;
LSelectMethod: TSelectMethod; LSelectMethod: TSelectMethod;
begin begin
if ATypeInfo = nil then if ATypeInfo = nil then
Exit(SelectBinaryEqualityComparer(Nil, ASize, AConstParaRef)) Exit(SelectBinaryEqualityComparer(Nil, ASize))
else else
begin begin
LInstance := @FExtendedEqualityComparerInstances[ATypeInfo.Kind]; LInstance := @FExtendedEqualityComparerInstances[ATypeInfo.Kind];
@ -2510,7 +2501,7 @@ begin
begin begin
TMethod(LSelectMethod).Code := LInstance.SelectorInstance; TMethod(LSelectMethod).Code := LInstance.SelectorInstance;
TMethod(LSelectMethod).Data := Self; TMethod(LSelectMethod).Data := Self;
Result := LSelectMethod(GetTypeData(ATypeInfo), ASize, AConstParaRef); Result := LSelectMethod(GetTypeData(ATypeInfo), ASize);
end; end;
end; end;
end; end;
@ -2639,7 +2630,7 @@ begin
if GetTypeKind(T) in TComparerService.UseBinaryMethods then if GetTypeKind(T) in TComparerService.UseBinaryMethods then
Result := TBinaryEqualityComparer<T>.Create(Nil) Result := TBinaryEqualityComparer<T>.Create(Nil)
else else
Result := _LookupVtableInfo(giEqualityComparer, TypeInfo(T), SizeOf(T), ConstParamIsRef<T>()); Result := _LookupVtableInfo(giEqualityComparer, TypeInfo(T), SizeOf(T));
end; end;
class function TEqualityComparer<T>.Default(AHashFactoryClass: THashFactoryClass): IEqualityComparer<T>; class function TEqualityComparer<T>.Default(AHashFactoryClass: THashFactoryClass): IEqualityComparer<T>;
@ -2647,9 +2638,9 @@ begin
if GetTypeKind(T) in TComparerService.UseBinaryMethods then if GetTypeKind(T) in TComparerService.UseBinaryMethods then
Result := TBinaryEqualityComparer<T>.Create(AHashFactoryClass) Result := TBinaryEqualityComparer<T>.Create(AHashFactoryClass)
else if AHashFactoryClass.InheritsFrom(TExtendedHashFactory) then else if AHashFactoryClass.InheritsFrom(TExtendedHashFactory) then
Result := _LookupVtableInfoEx(giExtendedEqualityComparer, TypeInfo(T), SizeOf(T), ConstParamIsRef<T>(), AHashFactoryClass) Result := _LookupVtableInfoEx(giExtendedEqualityComparer, TypeInfo(T), SizeOf(T), AHashFactoryClass)
else if AHashFactoryClass.InheritsFrom(THashFactory) then else if AHashFactoryClass.InheritsFrom(THashFactory) then
Result := _LookupVtableInfoEx(giEqualityComparer, TypeInfo(T), SizeOf(T), ConstParamIsRef<T>(), AHashFactoryClass); Result := _LookupVtableInfoEx(giEqualityComparer, TypeInfo(T), SizeOf(T), AHashFactoryClass);
end; end;
class function TEqualityComparer<T>.Construct(const AEqualityComparison: TOnEqualityComparison<T>; class function TEqualityComparer<T>.Construct(const AEqualityComparison: TOnEqualityComparison<T>;
@ -2791,7 +2782,7 @@ begin
if GetTypeKind(T) in TComparerService.UseBinaryMethods then if GetTypeKind(T) in TComparerService.UseBinaryMethods then
Result := TBinaryExtendedEqualityComparer<T>.Create(Nil) Result := TBinaryExtendedEqualityComparer<T>.Create(Nil)
else else
Result := _LookupVtableInfo(giExtendedEqualityComparer, TypeInfo(T), SizeOf(T), ConstParamIsRef<T>()); Result := _LookupVtableInfo(giExtendedEqualityComparer, TypeInfo(T), SizeOf(T));
end; end;
class function TExtendedEqualityComparer<T>.Default( class function TExtendedEqualityComparer<T>.Default(
@ -2801,7 +2792,7 @@ begin
if GetTypeKind(T) in TComparerService.UseBinaryMethods then if GetTypeKind(T) in TComparerService.UseBinaryMethods then
Result := TBinaryExtendedEqualityComparer<T>.Create(Nil) Result := TBinaryExtendedEqualityComparer<T>.Create(Nil)
else else
Result := _LookupVtableInfoEx(giExtendedEqualityComparer, TypeInfo(T), SizeOf(T), ConstParamIsRef<T>(), AExtenedHashFactoryClass); Result := _LookupVtableInfoEx(giExtendedEqualityComparer, TypeInfo(T), SizeOf(T), AExtenedHashFactoryClass);
end; end;
class function TExtendedEqualityComparer<T>.Construct( class function TExtendedEqualityComparer<T>.Construct(
@ -3383,25 +3374,25 @@ begin
Result := CompareMemRange(ALeft, ARight, ASize); Result := CompareMemRange(ALeft, ARight, ASize);
end; end;
function _LookupVtableInfo(AGInterface: TDefaultGenericInterface; ATypeInfo: PTypeInfo; ASize: SizeInt; AConstParaRef: Boolean): Pointer; function _LookupVtableInfo(AGInterface: TDefaultGenericInterface; ATypeInfo: PTypeInfo; ASize: SizeInt): Pointer;
begin begin
Result := _LookupVtableInfoEx(AGInterface, ATypeInfo, ASize, AConstParaRef, nil); Result := _LookupVtableInfoEx(AGInterface, ATypeInfo, ASize, nil);
end; end;
function _LookupVtableInfoEx(AGInterface: TDefaultGenericInterface; ATypeInfo: PTypeInfo; ASize: SizeInt; function _LookupVtableInfoEx(AGInterface: TDefaultGenericInterface; ATypeInfo: PTypeInfo; ASize: SizeInt;
AConstParaRef: Boolean; AFactory: THashFactoryClass): Pointer; AFactory: THashFactoryClass): Pointer;
begin begin
case AGInterface of case AGInterface of
giComparer: giComparer:
Exit( Exit(
TComparerService.LookupComparer(ATypeInfo, ASize, AConstParaRef)); TComparerService.LookupComparer(ATypeInfo, ASize));
giEqualityComparer: giEqualityComparer:
begin begin
if AFactory = nil then if AFactory = nil then
AFactory := TDefaultHashFactory; AFactory := TDefaultHashFactory;
Exit( Exit(
AFactory.GetHashService.LookupEqualityComparer(ATypeInfo, ASize, AConstParaRef)); AFactory.GetHashService.LookupEqualityComparer(ATypeInfo, ASize));
end; end;
giExtendedEqualityComparer: giExtendedEqualityComparer:
begin begin
@ -3409,7 +3400,7 @@ begin
AFactory := TDelphiDoubleHashFactory; AFactory := TDelphiDoubleHashFactory;
Exit( Exit(
TExtendedHashServiceClass(AFactory.GetHashService).LookupExtendedEqualityComparer(ATypeInfo, ASize, AConstParaRef)); TExtendedHashServiceClass(AFactory.GetHashService).LookupExtendedEqualityComparer(ATypeInfo, ASize));
end; end;
else else
System.Error(reRangeError); System.Error(reRangeError);