1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-20 17:08:00 +02:00

Delegate comparison expansion, hashable, == operator

This commit is contained in:
Brian Fiete 2022-02-15 09:31:23 -05:00
parent 9dcafb7db8
commit a3a8bfa40c
8 changed files with 157 additions and 18 deletions

View file

@ -1,17 +1,24 @@
namespace System
{
class Delegate
class Delegate : IHashable
{
void* mFuncPtr;
void* mTarget;
public static bool Equals(Delegate a, Delegate b)
{
if ((Object)a == (Object)b)
if (a === null)
return b === null;
return a.Equals(b);
}
public virtual bool Equals(Delegate val)
{
if (this === val)
return true;
if ((Object)a == null || (Object)b == null)
if (val == null)
return false;
return (a.mFuncPtr == b.mFuncPtr) && (a.mTarget == b.mTarget);
return (mFuncPtr == val.mFuncPtr) && (mTarget == val.mTarget);
}
public Result<void*> GetFuncPtr()
@ -37,6 +44,19 @@ namespace System
// Note- this is safe even if mTarget is not an object, because the GC does object address validation
GC.Mark(Internal.UnsafeCastToObject(mTarget));
}
public int GetHashCode()
{
return (int)mFuncPtr;
}
[Commutable]
public static bool operator==(Delegate a, Delegate b)
{
if (a === null)
return b === null;
return a.Equals(b);
}
}
delegate void Action();

View file

@ -418,7 +418,7 @@ namespace System
{
using (sMonitor.Val.Enter())
{
if (sErrorHandlers.Remove(handler))
if (sErrorHandlers.RemoveStrict(handler))
return .Ok;
}
return .Err;