1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Merge pull request #1363 from disarray2077/patch-5

Add bounds checking to [Pop]Back/[Pop]Front
This commit is contained in:
Brian Fiete 2022-01-08 12:31:52 +01:00 committed by GitHub
commit 849a305887
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -283,18 +283,32 @@ namespace System.Collections
public ref T Front
{
[Checked]
get
{
Runtime.Assert(mSize != 0);
return ref mItems[0];
}
[Unchecked, Inline]
get
{
Debug.Assert(mSize != 0);
return ref mItems[0];
}
}
public ref T Back
{
[Checked]
get
{
Runtime.Assert(mSize != 0);
return ref mItems[mSize - 1];
}
[Unchecked, Inline]
get
{
Debug.Assert(mSize != 0);
return ref mItems[mSize - 1];
}
}
@ -723,13 +737,29 @@ namespace System.Collections
return result;
}
[Checked]
public T PopBack()
{
T backVal = mItems[mSize - 1];
mSize--;
Runtime.Assert(mSize != 0);
return mItems[--mSize];
}
[Unchecked]
public T PopBack()
{
return mItems[--mSize];
}
[Checked]
public T PopFront()
{
Runtime.Assert(mSize != 0);
T backVal = mItems[0];
RemoveAt(0);
return backVal;
}
[Unchecked]
public T PopFront()
{
T backVal = mItems[0];