Skip to content

Commit b3d5f4b

Browse files
committed
Added Agressive inlining for methods in pointer
1 parent e5a41f8 commit b3d5f4b

File tree

2 files changed

+53
-48
lines changed

2 files changed

+53
-48
lines changed

DotnetNativeBase/DotnetNativeBase.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010
<PackageProjectUrl>https://github.com/DotnetNative/DotnetNativeBase</PackageProjectUrl>
1111
<RepositoryUrl>https://github.com/DotnetNative/DotnetNativeBase</RepositoryUrl>
1212
<PackageTags>naot korn dnb native</PackageTags>
13-
<Version>1.0.5</Version>
13+
<Version>1.0.6</Version>
1414
<Platforms>x64</Platforms>
1515
<PackageReadmeFile>PACK.md</PackageReadmeFile>
1616
<IncludeContentInPack>true</IncludeContentInPack>
1717
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
1818
</PropertyGroup>
1919
<ItemGroup>
20+
<Using Include="System.Runtime.CompilerServices" />
21+
<Using Include="System.Runtime.CompilerServices.MethodImplOptions">
22+
<Static>True</Static>
23+
</Using>
2024
<Using Include="System.Runtime.InteropServices" />
2125
<None Include="PACK.md">
2226
<Pack>true</Pack>

DotnetNativeBase/pointer.cs

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,55 +12,56 @@ public unsafe struct pointer
1212
public override int GetHashCode() => ((int)Address) ^ ((int)(Address >> 32));
1313

1414
#region Operators
15-
public static pointer operator +(pointer a, pointer b) => a.Address + b.Address;
16-
public static pointer operator -(pointer a, pointer b) => a.Address - b.Address;
17-
public static pointer operator ++(pointer self) => self.Address++;
18-
public static pointer operator --(pointer self) => self.Address--;
19-
public static pointer operator ~(pointer self) => ~self.Address;
20-
public static pointer operator *(pointer a, pointer b) => a.Address * b.Address;
21-
public static pointer operator /(pointer a, pointer b) => a.Address / b.Address;
22-
public static pointer operator %(pointer a, pointer b) => a.Address % b.Address;
23-
public static pointer operator &(pointer a, pointer b) => a.Address & b.Address;
24-
public static pointer operator ^(pointer a, pointer b) => a.Address ^ b.Address;
25-
public static pointer operator |(pointer a, pointer b) => a.Address | b.Address;
26-
public static pointer operator >>(pointer a, int shift) => a.Address >> shift;
27-
public static pointer operator <<(pointer a, int shift) => a.Address << shift;
28-
public static pointer operator >>>(pointer a, int shift) => a.Address >>> shift;
29-
public static bool operator <(pointer a, pointer b) => a.Address < b.Address;
30-
public static bool operator <=(pointer a, pointer b) => a.Address <= b.Address;
31-
public static bool operator >(pointer a, pointer b) => a.Address > b.Address;
32-
public static bool operator >=(pointer a, pointer b) => a.Address >= b.Address;
33-
public static bool operator ==(pointer a, pointer b) => a.Address == b.Address;
34-
public static bool operator !=(pointer a, pointer b) => a.Address != b.Address;
15+
[MethodImpl(AggressiveInlining)] public static pointer operator +(pointer a, pointer b) => a.Address + b.Address;
16+
[MethodImpl(AggressiveInlining)] public static pointer operator -(pointer a, pointer b) => a.Address - b.Address;
17+
[MethodImpl(AggressiveInlining)] public static pointer operator ++(pointer self) => self.Address++;
18+
[MethodImpl(AggressiveInlining)] public static pointer operator --(pointer self) => self.Address--;
19+
[MethodImpl(AggressiveInlining)] public static pointer operator ~(pointer self) => ~self.Address;
20+
[MethodImpl(AggressiveInlining)] public static pointer operator *(pointer a, pointer b) => a.Address * b.Address;
21+
[MethodImpl(AggressiveInlining)] public static pointer operator /(pointer a, pointer b) => a.Address / b.Address;
22+
[MethodImpl(AggressiveInlining)] public static pointer operator %(pointer a, pointer b) => a.Address % b.Address;
23+
[MethodImpl(AggressiveInlining)] public static pointer operator &(pointer a, pointer b) => a.Address & b.Address;
24+
[MethodImpl(AggressiveInlining)] public static pointer operator ^(pointer a, pointer b) => a.Address ^ b.Address;
25+
[MethodImpl(AggressiveInlining)] public static pointer operator |(pointer a, pointer b) => a.Address | b.Address;
26+
[MethodImpl(AggressiveInlining)] public static pointer operator >>(pointer a, int shift) => a.Address >> shift;
27+
[MethodImpl(AggressiveInlining)] public static pointer operator <<(pointer a, int shift) => a.Address << shift;
28+
[MethodImpl(AggressiveInlining)] public static pointer operator >>>(pointer a, int shift) => a.Address >>> shift;
29+
[MethodImpl(AggressiveInlining)] public static bool operator <(pointer a, pointer b) => a.Address < b.Address;
30+
[MethodImpl(AggressiveInlining)] public static bool operator <=(pointer a, pointer b) => a.Address <= b.Address;
31+
[MethodImpl(AggressiveInlining)] public static bool operator >(pointer a, pointer b) => a.Address > b.Address;
32+
[MethodImpl(AggressiveInlining)] public static bool operator >=(pointer a, pointer b) => a.Address >= b.Address;
33+
[MethodImpl(AggressiveInlining)] public static bool operator ==(pointer a, pointer b) => a.Address == b.Address;
34+
[MethodImpl(AggressiveInlining)] public static bool operator !=(pointer a, pointer b) => a.Address != b.Address;
3535
#endregion
3636

3737
#region Implicits
38-
public static implicit operator pointer(nint address) => new(address);
39-
public static implicit operator pointer(void* pointer) => new((nint)pointer);
40-
public static implicit operator pointer(void** pointer) => new((nint)pointer);
41-
public static implicit operator pointer(void*** pointer) => new((nint)pointer);
42-
public static implicit operator pointer(delegate* unmanaged<void> ptr) => new((nint)ptr);
43-
44-
public static implicit operator nint(pointer pointer) => pointer.Address;
45-
public static implicit operator nuint(pointer pointer) => (nuint)pointer.Address;
46-
public static implicit operator long(pointer pointer) => pointer.Address;
47-
public static implicit operator ulong(pointer pointer) => (ulong)pointer.Address;
48-
49-
public static implicit operator void*(pointer pointer) => (void*)pointer.Address;
50-
public static implicit operator void**(pointer pointer) => (void**)pointer.Address;
51-
public static implicit operator void***(pointer Sudden_Reference_To_Bocchi_The_Rock) => (void***)Sudden_Reference_To_Bocchi_The_Rock.Address;
52-
53-
public static implicit operator byte*(pointer pointer) => (byte*)pointer.Address;
54-
public static implicit operator sbyte*(pointer pointer) => (sbyte*)pointer.Address;
55-
public static implicit operator short*(pointer pointer) => (short*)pointer.Address;
56-
public static implicit operator ushort*(pointer pointer) => (ushort*)pointer.Address;
57-
public static implicit operator int*(pointer pointer) => (int*)pointer.Address;
58-
public static implicit operator uint*(pointer pointer) => (uint*)pointer.Address;
59-
public static implicit operator long*(pointer pointer) => (long*)pointer.Address;
60-
public static implicit operator ulong*(pointer pointer) => (ulong*)pointer.Address;
61-
public static implicit operator nint*(pointer pointer) => (nint*)pointer.Address;
62-
public static implicit operator nuint*(pointer pointer) => (nuint*)pointer.Address;
63-
64-
public static implicit operator delegate* unmanaged<void>(pointer pointer) => (delegate* unmanaged<void>)pointer;
38+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(nint address) => new(address);
39+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(nuint address) => new((nint)address);
40+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(long address) => new((nint)address);
41+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(ulong address) => new((nint)address);
42+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(int address) => new(address);
43+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(uint address) => new((nint)address);
44+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(void* pointer) => new((nint)pointer);
45+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(void** pointer) => new((nint)pointer);
46+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(void*** pointer) => new((nint)pointer);
47+
[MethodImpl(AggressiveInlining)] public static implicit operator pointer(delegate* unmanaged<void> ptr) => new((nint)ptr);
48+
[MethodImpl(AggressiveInlining)] public static implicit operator nint(pointer pointer) => pointer.Address;
49+
[MethodImpl(AggressiveInlining)] public static implicit operator nuint(pointer pointer) => (nuint)pointer.Address;
50+
[MethodImpl(AggressiveInlining)] public static implicit operator long(pointer pointer) => pointer.Address;
51+
[MethodImpl(AggressiveInlining)] public static implicit operator ulong(pointer pointer) => (ulong)pointer.Address;
52+
[MethodImpl(AggressiveInlining)] public static implicit operator void*(pointer pointer) => (void*)pointer.Address;
53+
[MethodImpl(AggressiveInlining)] public static implicit operator void**(pointer pointer) => (void**)pointer.Address;
54+
[MethodImpl(AggressiveInlining)] public static implicit operator void***(pointer Sudden_Reference_To_Bocchi_The_Rock) => (void***)Sudden_Reference_To_Bocchi_The_Rock.Address;
55+
[MethodImpl(AggressiveInlining)] public static implicit operator byte*(pointer pointer) => (byte*)pointer.Address;
56+
[MethodImpl(AggressiveInlining)] public static implicit operator sbyte*(pointer pointer) => (sbyte*)pointer.Address;
57+
[MethodImpl(AggressiveInlining)] public static implicit operator short*(pointer pointer) => (short*)pointer.Address;
58+
[MethodImpl(AggressiveInlining)] public static implicit operator ushort*(pointer pointer) => (ushort*)pointer.Address;
59+
[MethodImpl(AggressiveInlining)] public static implicit operator int*(pointer pointer) => (int*)pointer.Address;
60+
[MethodImpl(AggressiveInlining)] public static implicit operator uint*(pointer pointer) => (uint*)pointer.Address;
61+
[MethodImpl(AggressiveInlining)] public static implicit operator long*(pointer pointer) => (long*)pointer.Address;
62+
[MethodImpl(AggressiveInlining)] public static implicit operator ulong*(pointer pointer) => (ulong*)pointer.Address;
63+
[MethodImpl(AggressiveInlining)] public static implicit operator nint*(pointer pointer) => (nint*)pointer.Address;
64+
[MethodImpl(AggressiveInlining)] public static implicit operator nuint*(pointer pointer) => (nuint*)pointer.Address;
65+
[MethodImpl(AggressiveInlining)] public static implicit operator delegate* unmanaged<void>(pointer pointer) => (delegate* unmanaged<void>)pointer;
6566
#endregion
6667
}

0 commit comments

Comments
 (0)