Keyword mapping refactoring
This commit is contained in:
+22
-15
@@ -504,12 +504,12 @@ begin
|
||||
if (not Assigned(Self.FDefinition)) or (not Assigned(otherDef)) then
|
||||
exit(False);
|
||||
|
||||
if Length(Self.FDefinition.Fields) <> Length(otherDef.Fields) then
|
||||
if Self.FDefinition.Count <> otherDef.Count then
|
||||
exit(False);
|
||||
|
||||
for i := 0 to High(Self.FDefinition.Fields) do
|
||||
for i := 0 to Self.FDefinition.Count - 1 do
|
||||
begin
|
||||
if (Self.FDefinition.Fields[i].Key <> otherDef.Fields[i].Key) or (Self.FDefinition.Fields[i].Value <> otherDef.Fields[i].Value) then
|
||||
if (Self.FDefinition[i].Key <> otherDef[i].Key) or (Self.FDefinition[i].Value <> otherDef[i].Value) then
|
||||
exit(False);
|
||||
end;
|
||||
|
||||
@@ -518,13 +518,15 @@ end;
|
||||
|
||||
function TRecordType.GetHashCode: Integer;
|
||||
var
|
||||
i: Integer;
|
||||
field: TPair<IKeyword, TScalar.TKind>;
|
||||
begin
|
||||
Result := Ord(GetKind);
|
||||
if Assigned(FDefinition) then
|
||||
begin
|
||||
for field in FDefinition.Fields do
|
||||
for i := 0 to FDefinition.Count - 1 do
|
||||
begin
|
||||
field := FDefinition[i];
|
||||
var hash := TEqualityComparer<IKeyword>.Default.GetHashCode(field.Key);
|
||||
Result := THashBobJenkins.GetHashValue(hash, SizeOf(Pointer), Result);
|
||||
var data := Ord(field.Value);
|
||||
@@ -536,14 +538,16 @@ end;
|
||||
function TRecordType.ToString: string;
|
||||
var
|
||||
i: Integer;
|
||||
field: TPair<IKeyword, TScalar.TKind>;
|
||||
begin
|
||||
Result := GetKind.ToString + '{';
|
||||
if Assigned(FDefinition) then
|
||||
begin
|
||||
for i := 0 to High(FDefinition.Fields) do
|
||||
for i := 0 to FDefinition.Count - 1 do
|
||||
begin
|
||||
Result := Result + FDefinition.Fields[i].Key.Name + ': ' + FDefinition.Fields[i].Value.ToString;
|
||||
if i < High(FDefinition.Fields) then
|
||||
field := FDefinition[i];
|
||||
Result := Result + field.Key.Name + ': ' + field.Value.ToString;
|
||||
if i < FDefinition.Count - 1 then
|
||||
Result := Result + ', ';
|
||||
end;
|
||||
end;
|
||||
@@ -591,13 +595,12 @@ begin
|
||||
if (not Assigned(Self.FDefinition)) or (not Assigned(otherDef)) then
|
||||
exit(False);
|
||||
|
||||
if Length(Self.FDefinition.Fields) <> Length(otherDef.Fields) then
|
||||
if Self.FDefinition.Count <> otherDef.Count then
|
||||
exit(False);
|
||||
|
||||
for i := 0 to High(Self.FDefinition.Fields) do
|
||||
for i := 0 to Self.FDefinition.Count - 1 do
|
||||
begin
|
||||
if (Self.FDefinition.Fields[i].Key <> otherDef.Fields[i].Key)
|
||||
or (not Self.FDefinition.Fields[i].Value.IsEqual(otherDef.Fields[i].Value)) then
|
||||
if (Self.FDefinition[i].Key <> otherDef[i].Key) or (not Self.FDefinition[i].Value.IsEqual(otherDef[i].Value)) then
|
||||
exit(False);
|
||||
end;
|
||||
|
||||
@@ -606,13 +609,15 @@ end;
|
||||
|
||||
function TGenericRecordType.GetHashCode: Integer;
|
||||
var
|
||||
i: Integer;
|
||||
field: TPair<IKeyword, IStaticType>;
|
||||
begin
|
||||
Result := Ord(stGenericRecord);
|
||||
if Assigned(FDefinition) then
|
||||
begin
|
||||
for field in FDefinition.Fields do
|
||||
for i := 0 to FDefinition.Count - 1 do
|
||||
begin
|
||||
field := FDefinition[i];
|
||||
var data := TEqualityComparer<IKeyword>.Default.GetHashCode(field.Key);
|
||||
Result := THashBobJenkins.GetHashValue(data, SizeOf(Pointer), Result);
|
||||
if Assigned(field.Value) then
|
||||
@@ -627,14 +632,16 @@ end;
|
||||
function TGenericRecordType.ToString: string;
|
||||
var
|
||||
i: Integer;
|
||||
field: TPair<IKeyword, IStaticType>;
|
||||
begin
|
||||
Result := GetKind.ToString + '{';
|
||||
if Assigned(FDefinition) then
|
||||
begin
|
||||
for i := 0 to High(FDefinition.Fields) do
|
||||
for i := 0 to FDefinition.Count - 1 do
|
||||
begin
|
||||
Result := Result + FDefinition.Fields[i].Key.Name + ': ' + FDefinition.Fields[i].Value.ToString;
|
||||
if i < High(FDefinition.Fields) then
|
||||
field := FDefinition[i];
|
||||
Result := Result + field.Key.Name + ': ' + field.Value.ToString;
|
||||
if i < FDefinition.Count - 1 then
|
||||
Result := Result + ', ';
|
||||
end;
|
||||
end;
|
||||
|
||||
Reference in New Issue
Block a user