mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-25 19:01:02 +00:00
Improved and documented IEquatable vs IComparable
This commit is contained in:
parent
358bcd4f88
commit
c175a486fc
|
@ -313,8 +313,9 @@ namespace Bind.Structures
|
||||||
public int CompareTo(Type other)
|
public int CompareTo(Type other)
|
||||||
{
|
{
|
||||||
// Make sure that Pointer parameters are sorted last to avoid bug [#1098].
|
// Make sure that Pointer parameters are sorted last to avoid bug [#1098].
|
||||||
// The rest of the comparisons are not important, but they are there to
|
// The rest of the comparisons help maintain a stable order (useful for source control).
|
||||||
// guarantee a stable order between program executions.
|
// Note that CompareTo is stricter than Equals and that there is code in
|
||||||
|
// DelegateCollection.Add that depends on this fact.
|
||||||
int result = this.CurrentType.CompareTo(other.CurrentType);
|
int result = this.CurrentType.CompareTo(other.CurrentType);
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
result = Pointer.CompareTo(other.Pointer); // Must come after array/ref, see issue [#1098]
|
result = Pointer.CompareTo(other.Pointer); // Must come after array/ref, see issue [#1098]
|
||||||
|
@ -322,6 +323,10 @@ namespace Bind.Structures
|
||||||
result = Reference.CompareTo(other.Reference);
|
result = Reference.CompareTo(other.Reference);
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
result = Array.CompareTo(other.Array);
|
result = Array.CompareTo(other.Array);
|
||||||
|
// Note: CLS-compliance and element counts
|
||||||
|
// are used for comparison calculations, in order
|
||||||
|
// to maintain a stable sorting order, even though
|
||||||
|
// they are not used in equality calculations.
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
result = CLSCompliant.CompareTo(other.CLSCompliant);
|
result = CLSCompliant.CompareTo(other.CLSCompliant);
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
|
@ -335,7 +340,18 @@ namespace Bind.Structures
|
||||||
|
|
||||||
public bool Equals(Type other)
|
public bool Equals(Type other)
|
||||||
{
|
{
|
||||||
return CompareTo(other) == 0;
|
bool result =
|
||||||
|
CurrentType.Equals(other.CurrentType) &&
|
||||||
|
Pointer.Equals(other.Pointer) &&
|
||||||
|
Reference.Equals(other.Reference) &&
|
||||||
|
Array.Equals(other.Array);
|
||||||
|
// Note: CLS-compliance and element count do not factor
|
||||||
|
// factor into the equality calculations, i.e.
|
||||||
|
// Foo(single[]) == Foo(single[]) -> true
|
||||||
|
// even if these types have different element counts.
|
||||||
|
// This is necessary because otherwise we'd get
|
||||||
|
// redefinition errors in the generated bindings.
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
Loading…
Reference in a new issue