-
Notifications
You must be signed in to change notification settings - Fork 7
/
Util.cs
45 lines (38 loc) · 1.28 KB
/
Util.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Backend.Data.Enum;
namespace Backend;
public static class Util
{
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
public static void RunStaticConstructor()
{
foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
RuntimeHelpers.RunClassConstructor(type.TypeHandle);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static PieceColor OppositeColor(PieceColor color) => (PieceColor)((int)color ^ 0x1);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
// ReSharper disable once InconsistentNaming
public static ref T AA<T>(this T[] array, int index)
{
#if DEBUG
return ref array[index];
#else
return ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(array), index);
#endif
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
// ReSharper disable once InconsistentNaming
public static ref T DJAA<T>(this T[][] array, int firstIndex, int secondIndex)
{
#if DEBUG
return ref array.AA(firstIndex)[secondIndex];
#else
return
ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(array.AA(firstIndex)), secondIndex);
#endif
}
}