Skip to content

Commit

Permalink
Merge pull request #82240 from jaros3/vector2i-gethashcode
Browse files Browse the repository at this point in the history
[C#] Use `HashCode.Combine()` for basic composite types instead of xor
  • Loading branch information
akien-mga committed Sep 26, 2023
2 parents 48bee5c + f1bab5f commit 42011d8
Show file tree
Hide file tree
Showing 16 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion modules/mono/glue/GodotSharp/GodotSharp/Core/Aabb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ public readonly bool IsEqualApprox(Aabb other)
/// <returns>A hash code for this AABB.</returns>
public override readonly int GetHashCode()
{
return _position.GetHashCode() ^ _size.GetHashCode();
return HashCode.Combine(_position, _size);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ public readonly bool IsEqualApprox(Basis other)
/// <returns>A hash code for this basis.</returns>
public override readonly int GetHashCode()
{
return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode();
return HashCode.Combine(Row0, Row1, Row2);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ public readonly bool IsEqualApprox(Color other)
/// <returns>A hash code for this color.</returns>
public override readonly int GetHashCode()
{
return R.GetHashCode() ^ G.GetHashCode() ^ B.GetHashCode() ^ A.GetHashCode();
return HashCode.Combine(R, G, B, A);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public readonly bool IsEqualApprox(Plane other)
/// <returns>A hash code for this plane.</returns>
public override readonly int GetHashCode()
{
return _normal.GetHashCode() ^ _d.GetHashCode();
return HashCode.Combine(_normal, _d);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ public readonly bool Equals(Projection other)
/// <returns>A hash code for this projection.</returns>
public override readonly int GetHashCode()
{
return Y.GetHashCode() ^ X.GetHashCode() ^ Z.GetHashCode() ^ W.GetHashCode();
return HashCode.Combine(X, Y, Z, W);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ public readonly bool IsEqualApprox(Quaternion other)
/// <returns>A hash code for this quaternion.</returns>
public override readonly int GetHashCode()
{
return Y.GetHashCode() ^ X.GetHashCode() ^ Z.GetHashCode() ^ W.GetHashCode();
return HashCode.Combine(X, Y, Z, W);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ public readonly bool IsEqualApprox(Rect2 other)
/// <returns>A hash code for this rect.</returns>
public override readonly int GetHashCode()
{
return _position.GetHashCode() ^ _size.GetHashCode();
return HashCode.Combine(_position, _size);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2I.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public readonly bool Equals(Rect2I other)
/// <returns>A hash code for this rect.</returns>
public override readonly int GetHashCode()
{
return _position.GetHashCode() ^ _size.GetHashCode();
return HashCode.Combine(_position, _size);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ public readonly bool IsEqualApprox(Transform2D other)
/// <returns>A hash code for this transform.</returns>
public override readonly int GetHashCode()
{
return X.GetHashCode() ^ Y.GetHashCode() ^ Origin.GetHashCode();
return HashCode.Combine(X, Y, Origin);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ public readonly bool IsEqualApprox(Transform3D other)
/// <returns>A hash code for this transform.</returns>
public override readonly int GetHashCode()
{
return Basis.GetHashCode() ^ Origin.GetHashCode();
return HashCode.Combine(Basis, Origin);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ public readonly bool IsZeroApprox()
/// <returns>A hash code for this vector.</returns>
public override readonly int GetHashCode()
{
return Y.GetHashCode() ^ X.GetHashCode();
return HashCode.Combine(X, Y);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2I.cs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ public readonly bool Equals(Vector2I other)
/// <returns>A hash code for this vector.</returns>
public override readonly int GetHashCode()
{
return Y.GetHashCode() ^ X.GetHashCode();
return HashCode.Combine(X, Y);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ public readonly bool IsZeroApprox()
/// <returns>A hash code for this vector.</returns>
public override readonly int GetHashCode()
{
return Y.GetHashCode() ^ X.GetHashCode() ^ Z.GetHashCode();
return HashCode.Combine(X, Y, Z);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3I.cs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ public readonly bool Equals(Vector3I other)
/// <returns>A hash code for this vector.</returns>
public override readonly int GetHashCode()
{
return Y.GetHashCode() ^ X.GetHashCode() ^ Z.GetHashCode();
return HashCode.Combine(X, Y, Z);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ public readonly bool IsZeroApprox()
/// <returns>A hash code for this vector.</returns>
public override readonly int GetHashCode()
{
return Y.GetHashCode() ^ X.GetHashCode() ^ Z.GetHashCode() ^ W.GetHashCode();
return HashCode.Combine(X, Y, Z, W);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4I.cs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ public readonly bool Equals(Vector4I other)
/// <returns>A hash code for this vector.</returns>
public override readonly int GetHashCode()
{
return Y.GetHashCode() ^ X.GetHashCode() ^ Z.GetHashCode() ^ W.GetHashCode();
return HashCode.Combine(X, Y, Z, W);
}

/// <summary>
Expand Down

0 comments on commit 42011d8

Please sign in to comment.