1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-20 08:58:00 +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

@ -211,6 +211,65 @@ namespace System.Collections
}
}
public ref T this[Index index]
{
[Checked]
get
{
int idx;
switch (index)
{
case .FromFront(let offset): idx = offset;
case .FromEnd(let offset): idx = mSize - 1 - offset;
}
Runtime.Assert((uint)idx < (uint)mSize);
return ref mItems[idx];
}
[Unchecked, Inline]
get
{
int idx;
switch (index)
{
case .FromFront(let offset): idx = offset;
case .FromEnd(let offset): idx = mSize - 1 - offset;
}
return ref mItems[idx];
}
[Checked]
set
{
int idx;
switch (index)
{
case .FromFront(let offset): idx = offset;
case .FromEnd(let offset): idx = mSize - 1 - offset;
}
Runtime.Assert((uint)idx < (uint)mSize);
mItems[idx] = value;
#if VERSION_LIST
mVersion++;
#endif
}
[Unchecked, Inline]
set
{
int idx;
switch (index)
{
case .FromFront(let offset): idx = offset;
case .FromEnd(let offset): idx = mSize - 1 - offset;
}
mItems[idx] = value;
#if VERSION_LIST
mVersion++;
#endif
}
}
public Span<T> this[IndexRange range]
{
#if !DEBUG