Skip to content

Commit 88b158e

Browse files
Feedback 3
1 parent 5c0558a commit 88b158e

File tree

2 files changed

+17
-96
lines changed

2 files changed

+17
-96
lines changed

src/linker/Linker.Dataflow/ValueNode.cs

Lines changed: 13 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ public override bool Equals (ValueNode other)
555555

556556
public override int GetHashCode ()
557557
{
558-
return HashUtils.CalcHashCode (Kind, TypeRepresented);
558+
return HashCode.Combine(Kind, TypeRepresented);
559559
}
560560

561561
protected override string NodeToString ()
@@ -589,7 +589,7 @@ public override bool Equals (ValueNode other)
589589

590590
public override int GetHashCode ()
591591
{
592-
return HashUtils.CalcHashCode (Kind, TypeRepresented);
592+
return HashCode.Combine (Kind, TypeRepresented);
593593
}
594594

595595
protected override string NodeToString ()
@@ -623,7 +623,7 @@ public override bool Equals (ValueNode other)
623623

624624
public override int GetHashCode ()
625625
{
626-
return HashUtils.CalcHashCode (Kind, Contents);
626+
return HashCode.Combine (Kind, Contents);
627627
}
628628

629629
protected override string NodeToString ()
@@ -657,7 +657,7 @@ public override bool Equals (ValueNode other)
657657

658658
public override int GetHashCode ()
659659
{
660-
return HashUtils.CalcHashCode (Kind, ParameterIndex);
660+
return HashCode.Combine (Kind, ParameterIndex);
661661
}
662662

663663
protected override string NodeToString ()
@@ -772,7 +772,7 @@ public override bool Equals (ValueNode other)
772772

773773
public override int GetHashCode ()
774774
{
775-
return HashUtils.CalcHashCode (Kind, Values);
775+
return HashCode.Combine (Kind, Values);
776776
}
777777

778778
protected override string NodeToString ()
@@ -863,7 +863,7 @@ public override bool Equals (ValueNode other)
863863

864864
public override int GetHashCode ()
865865
{
866-
return HashUtils.CalcHashCode (Kind, AssemblyIdentity, NameString);
866+
return HashCode.Combine (Kind, AssemblyIdentity, NameString);
867867
}
868868

869869
protected override string NodeToString ()
@@ -923,7 +923,7 @@ public override bool Equals (ValueNode other)
923923

924924
public override int GetHashCode ()
925925
{
926-
return HashUtils.CalcHashCode (Kind, Field, InstanceValue);
926+
return HashCode.Combine (Kind, Field, InstanceValue);
927927
}
928928

929929
protected override string NodeToString ()
@@ -947,7 +947,7 @@ public ConstIntValue (int value)
947947

948948
public override int GetHashCode ()
949949
{
950-
return HashUtils.CalcHashCode (Kind, Value);
950+
return HashCode.Combine (Kind, Value);
951951
}
952952

953953
public override bool Equals (ValueNode other)
@@ -984,7 +984,7 @@ public ArrayValue (ValueNode size)
984984

985985
public override int GetHashCode ()
986986
{
987-
return HashUtils.CalcHashCode (Kind, Size);
987+
return HashCode.Combine (Kind, Size);
988988
}
989989

990990
public override bool Equals (ValueNode other)
@@ -1087,95 +1087,12 @@ public override bool Equals (object other)
10871087

10881088
static class HashUtils
10891089
{
1090-
[MethodImpl (MethodImplOptions.AggressiveInlining)]
1091-
static int _rotl (this int value, int shift)
1092-
{
1093-
return (int)(((uint)value << shift) | ((uint)value >> (32 - shift)));
1094-
}
1095-
10961090
public static int CalcHashCodeEnumerable<T> (IEnumerable<T> list) where T : class
10971091
{
1098-
int length = list.Count ();
1099-
1100-
int hash1 = 0x449b3ad6;
1101-
int hash2 = (length << 3) + 0x55399219;
1102-
1103-
int index = 0;
1104-
1105-
T element1 = null;
1106-
T element2 = null;
1107-
1108-
foreach (T element in list) {
1109-
if ((index++ & 1) == 0) {
1110-
element1 = element;
1111-
continue;
1112-
}
1113-
element2 = element;
1114-
1115-
hash1 = (hash1 + _rotl (hash1, 5)) ^ element1.GetHashCode();
1116-
hash2 = (hash2 + _rotl (hash2, 5)) ^ element2.GetHashCode();
1117-
}
1118-
1119-
// If we had an odd length, we haven't included the last element yet.
1120-
if ((length & 1) != 0)
1121-
hash1 = (hash1 + _rotl (hash1, 5)) ^ element1.GetHashCode();
1122-
1123-
hash1 += _rotl (hash1, 8);
1124-
hash2 += _rotl (hash2, 8);
1125-
1126-
return hash1 ^ hash2;
1127-
}
1128-
1129-
public static int CalcHashCode<T1> (ValueNodeKind kind, T1 obj1)
1130-
where T1 : class
1131-
{
1132-
return CalcHashCode (kind, obj1.GetHashCode());
1133-
}
1134-
1135-
public static int CalcHashCode (ValueNodeKind kind, int val1)
1136-
{
1137-
return CalcHashCode (kind.GetHashCode (), val1);
1138-
}
1139-
1140-
public static int CalcHashCode (int hashCode1, int hashCode2)
1141-
{
1142-
int length = 2;
1143-
1144-
int hash1 = 0x449b3ad6;
1145-
int hash2 = (length << 3) + 0x55399219;
1146-
1147-
hash1 = (hash1 + _rotl (hash1, 5)) ^ hashCode1;
1148-
hash2 = (hash2 + _rotl (hash2, 5)) ^ hashCode2;
1149-
1150-
hash1 += _rotl (hash1, 8);
1151-
hash2 += _rotl (hash2, 8);
1152-
1153-
return hash1 ^ hash2;
1154-
}
1155-
1156-
public static int CalcHashCode<T1, T2> (ValueNodeKind kind, T1 obj1, T2 obj2)
1157-
where T1 : class
1158-
where T2 : class
1159-
1160-
{
1161-
return CalcHashCode (kind, obj1.GetHashCode(), obj2.GetHashCode());
1162-
}
1163-
1164-
static int CalcHashCode (ValueNodeKind kind, int hashCode1, int hashCode2)
1165-
{
1166-
int length = 3;
1167-
1168-
int hash1 = 0x449b3ad6;
1169-
int hash2 = (length << 3) + 0x55399219;
1170-
1171-
hash1 = (hash1 + _rotl (hash1, 5)) ^ kind.GetHashCode ();
1172-
hash2 = (hash2 + _rotl (hash2, 5)) ^ hashCode1;
1173-
hash1 = (hash1 + _rotl (hash1, 5)) ^ hashCode2;
1174-
1175-
hash1 += _rotl (hash1, 8);
1176-
hash2 += _rotl (hash2, 8);
1177-
1178-
return hash1 ^ hash2;
1092+
HashCode hashCode = new HashCode ();
1093+
foreach (var item in list)
1094+
hashCode.Add (item);
1095+
return hashCode.ToHashCode ();
11791096
}
11801097
}
11811098
}

src/linker/Mono.Linker.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
<Compile Remove="Linker.Steps\ResolveFromXApiStep.cs" />
4242
</ItemGroup>
4343

44+
<ItemGroup>
45+
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.0" />
46+
</ItemGroup>
47+
4448
<ItemGroup>
4549
<ProjectReference Include="..\..\external\cecil\Mono.Cecil.csproj" />
4650
<ProjectReference Include="..\..\external\cecil\symbols\pdb\Mono.Cecil.Pdb.csproj" />

0 commit comments

Comments
 (0)