Skip to content

Commit

Permalink
Reduced IL usage
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Jan 13, 2024
1 parent fba89db commit 83df778
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/DotNext.Tests/Runtime/IntrinsicsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,11 @@ public static void TypeAlignment()
Equal(8, Intrinsics.AlignOf<ValueTuple<byte, long>>());
Equal(IntPtr.Size, Intrinsics.AlignOf<string>());
}

[Fact]
public static unsafe void PtrHashCode()
{
nint expected = 10;
Equal(expected.GetHashCode(), Intrinsics.PointerHashCode(expected.ToPointer()));
}
}
6 changes: 1 addition & 5 deletions src/DotNext/Runtime/Intrinsics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ public static T Cast<T>(object? obj)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[CLSCompliant(false)]
public static unsafe int PointerHashCode([In] void* pointer)
{
Ldarga(nameof(pointer));
Call(Method(Type<UIntPtr>(), nameof(UIntPtr.GetHashCode)));
return Return<int>();
}
=> ((nuint*)&pointer)->GetHashCode();

/// <summary>
/// Returns an address of the given by-ref parameter.
Expand Down

0 comments on commit 83df778

Please sign in to comment.