mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-12 05:14:10 +02:00
System.Index support
This commit is contained in:
parent
27fd5552cc
commit
05a65287d3
3 changed files with 124 additions and 1 deletions
|
@ -260,6 +260,35 @@ namespace System
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ref T this[Index index]
|
||||||
|
{
|
||||||
|
[Checked, Inline]
|
||||||
|
get
|
||||||
|
{
|
||||||
|
int idx;
|
||||||
|
switch (index)
|
||||||
|
{
|
||||||
|
case .FromFront(let offset): idx = offset;
|
||||||
|
case .FromEnd(let offset): idx = mLength - 1 - offset;
|
||||||
|
}
|
||||||
|
if ((uint)idx >= (uint)mLength)
|
||||||
|
Internal.ThrowIndexOutOfRange(1);
|
||||||
|
return ref (&mFirstElement)[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
[Unchecked, Inline]
|
||||||
|
get
|
||||||
|
{
|
||||||
|
int idx;
|
||||||
|
switch (index)
|
||||||
|
{
|
||||||
|
case .FromFront(let offset): idx = offset;
|
||||||
|
case .FromEnd(let offset): idx = mLength - 1 - offset;
|
||||||
|
}
|
||||||
|
return ref (&mFirstElement)[idx];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Span<T> this[IndexRange range]
|
public Span<T> this[IndexRange range]
|
||||||
{
|
{
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
|
|
|
@ -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]
|
public Span<T> this[IndexRange range]
|
||||||
{
|
{
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
|
|
|
@ -127,13 +127,48 @@ namespace System
|
||||||
|
|
||||||
public ref T this[int index]
|
public ref T this[int index]
|
||||||
{
|
{
|
||||||
[Inline]
|
[Checked]
|
||||||
get
|
get
|
||||||
|
{
|
||||||
|
Runtime.Assert((uint)index < (uint)mLength);
|
||||||
|
return ref mPtr[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
[Unchecked, Inline]
|
||||||
|
get
|
||||||
{
|
{
|
||||||
return ref mPtr[index];
|
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]
|
public Span<T> this[IndexRange range]
|
||||||
{
|
{
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue