1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-21 09:27:59 +02:00

System.Index support

This commit is contained in:
Brian Fiete 2021-10-24 08:24:53 -07:00
parent 27fd5552cc
commit 05a65287d3
3 changed files with 124 additions and 1 deletions

View file

@ -127,13 +127,48 @@ namespace System
public ref T this[int index]
{
[Inline]
[Checked]
get
{
Runtime.Assert((uint)index < (uint)mLength);
return ref mPtr[index];
}
[Unchecked, Inline]
get
{
return ref mPtr[index];
}
}
public ref T this[Index index]
{
[Checked]
get
{
int idx;
switch (index)
{
case .FromFront(let offset): idx = offset;
case .FromEnd(let offset): idx = mLength - 1 - offset;
}
Runtime.Assert((uint)idx < (uint)mLength);
return ref mPtr[idx];
}
[Unchecked, Inline]
get
{
int idx;
switch (index)
{
case .FromFront(let offset): idx = offset;
case .FromEnd(let offset): idx = mLength - 1 - offset;
}
return ref mPtr[idx];
}
}
public Span<T> this[IndexRange range]
{
#if !DEBUG