-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extended RcStackArray up to 512 elements (#41)
- Loading branch information
Showing
11 changed files
with
3,637 additions
and
30 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace DotRecast.Core.Collections | ||
{ | ||
public struct RcStackArray16<T> | ||
{ | ||
public static RcStackArray16<T> Empty => new RcStackArray16<T>(); | ||
|
||
private const int Size = 16; | ||
public int Length => Size; | ||
|
||
public T V0; | ||
public T V1; | ||
public T V2; | ||
public T V3; | ||
public T V4; | ||
public T V5; | ||
public T V6; | ||
public T V7; | ||
public T V8; | ||
public T V9; | ||
public T V10; | ||
public T V11; | ||
public T V12; | ||
public T V13; | ||
public T V14; | ||
public T V15; | ||
|
||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
private void ThrowExceptionIfIndexOutOfRange(int index) | ||
{ | ||
if (0 > index || index >= Size) | ||
{ | ||
throw new IndexOutOfRangeException($"{index}"); | ||
} | ||
} | ||
|
||
public T this[int index] | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
get | ||
{ | ||
ThrowExceptionIfIndexOutOfRange(index); | ||
|
||
return index switch | ||
{ | ||
0 => V0, | ||
1 => V1, | ||
2 => V2, | ||
3 => V3, | ||
4 => V4, | ||
5 => V5, | ||
6 => V6, | ||
7 => V7, | ||
8 => V8, | ||
9 => V9, | ||
10 => V10, | ||
11 => V11, | ||
12 => V12, | ||
13 => V13, | ||
14 => V14, | ||
15 => V15, | ||
_ => throw new IndexOutOfRangeException($"{index}") | ||
}; | ||
} | ||
|
||
set | ||
{ | ||
ThrowExceptionIfIndexOutOfRange(index); | ||
|
||
switch (index) | ||
{ | ||
case 0: V0 = value; break; | ||
case 1: V1 = value; break; | ||
case 2: V2 = value; break; | ||
case 3: V3 = value; break; | ||
case 4: V4 = value; break; | ||
case 5: V5 = value; break; | ||
case 6: V6 = value; break; | ||
case 7: V7 = value; break; | ||
case 8: V8 = value; break; | ||
case 9: V9 = value; break; | ||
case 10: V10 = value; break; | ||
case 11: V11 = value; break; | ||
case 12: V12 = value; break; | ||
case 13: V13 = value; break; | ||
case 14: V14 = value; break; | ||
case 15: V15 = value; break; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace DotRecast.Core.Collections | ||
{ | ||
public struct RcStackArray2<T> | ||
{ | ||
public static RcStackArray2<T> Empty => new RcStackArray2<T>(); | ||
|
||
private const int Size = 2; | ||
public int Length => Size; | ||
|
||
public T V0; | ||
public T V1; | ||
|
||
public T this[int index] | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
get | ||
{ | ||
ThrowHelper.ThrowExceptionIfIndexOutOfRange(index, Length); | ||
|
||
return index switch | ||
{ | ||
0 => V0, | ||
1 => V1, | ||
_ => throw new IndexOutOfRangeException($"{index}") | ||
}; | ||
} | ||
|
||
set | ||
{ | ||
ThrowHelper.ThrowExceptionIfIndexOutOfRange(index, Length); | ||
|
||
switch (index) | ||
{ | ||
case 0: V0 = value; break; | ||
case 1: V1 = value; break; | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.