Skip to content
Open
Changes from 2 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
16 changes: 13 additions & 3 deletions src/Engine/ProtoCore/FFI/CLRObjectMarshaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Xml;
using Autodesk.DesignScript.Interfaces;
using DesignScript.Builtin;
Expand Down Expand Up @@ -1394,8 +1395,17 @@ void core_Dispose(ProtoCore.RuntimeCore sender)
}

/// <summary>
/// This class compares two CLR objects. It is used in CLRObjectMap to
/// avoid hash collision.
/// This class compares two CLR objects using reference equality. It is used in CLRObjectMap
/// to map CLR object instances to their marshaled StackValue representations. Uses
/// <see cref="RuntimeHelpers.GetHashCode"/> to get the object's identity hash code, which
/// ensures well-distributed hash codes even when objects have value-based hash codes that
/// collide (e.g., Point objects with identical coordinates).
/// <para>
/// <b>Note:</b> The hash code computation is intentionally aligned with the reference
/// equality behavior used by <see cref="object.ReferenceEquals"/>. This ensures consistent
/// semantics between equality comparison and hash code generation, which is a requirement
/// for proper <see cref="IEqualityComparer{T}"/> implementation.
/// </para>
/// </summary>
public class ReferenceEqualityComparer: IEqualityComparer<object>
{
Expand All @@ -1406,7 +1416,7 @@ bool IEqualityComparer<object>.Equals(object x, object y)

public int GetHashCode(object obj)
{
return obj.GetHashCode();
return RuntimeHelpers.GetHashCode(obj);
}
}

Expand Down
Loading