Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#: Use HashCode.Combine() for basic composite types instead of xor #82240

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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