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

Corlib helper methods

This commit is contained in:
Brian Fiete 2022-08-26 15:42:35 -07:00
parent 6eddf12948
commit 74b73e5dc8
5 changed files with 116 additions and 2 deletions

View file

@ -363,6 +363,44 @@ namespace System
return .(this);
}
public void SetAll(T value)
{
for (int i < mLength)
(&mFirstElement)[i] = value;
}
public bool Contains(T value)
{
for (int i = 0; i < mLength; i++)
if ((&mFirstElement)[i] == value)
return true;
return false;
}
public bool ContainsStrict(T value)
{
for (int i = 0; i < mLength; i++)
if ((&mFirstElement)[i] === value)
return true;
return false;
}
public int IndexOf(T value)
{
for (int i = 0; i < mLength; i++)
if ((&mFirstElement)[i] == value)
return i;
return -1;
}
public int IndexOfStrict(T value)
{
for (int i = 0; i < mLength; i++)
if ((&mFirstElement)[i] === value)
return i;
return -1;
}
protected override void GCMarkMembers()
{
let type = typeof(T);

View file

@ -551,6 +551,14 @@ namespace System.Collections
mSize = (.)size;
}
public void Resize(int newSize, T fillValue)
{
let prevSize = mSize;
Count = newSize;
for (int i = prevSize; i < newSize; i++)
mItems[i] = fillValue;
}
public Enumerator GetEnumerator()
{
return Enumerator(this);
@ -636,6 +644,19 @@ namespace System.Collections
return -1;
}
public void Set(Span<T> span)
{
Count = span.Length;
for (int i < mSize)
mItems[i] = span[i];
}
public void SetAll(T value)
{
for (int i < mSize)
mItems[i] = value;
}
public void Insert(int index, T item)
{
var item; // This creates a copy - required if item is a ref to an element

View file

@ -292,6 +292,13 @@ namespace System
Runtime.FatalError("Assert failed");
}
[Comptime(ConstEval = true)]
public static void Assert(bool cond, String message)
{
if (!cond)
Runtime.FatalError(message);
}
static extern void Comptime_SetReturnType(int32 typeId);
static extern void* Comptime_MethodBuilder_EmitStr(void* native, StringView str);
static extern void* Comptime_CreateMethod(int32 typeId, StringView methodName, Type returnType, MethodFlags methodFlags);

View file

@ -15,8 +15,6 @@ namespace System
}
}
public explicit static operator T[CSize] (Self val)
{
return val.mVal;
@ -28,6 +26,44 @@ namespace System
return .(&val.mVal, CSize);
}
public void SetAll(T value)
{
for (int i < CSize)
mVal[i] = value;
}
public bool Contains(T value)
{
for (int i = 0; i < CSize; i++)
if (mVal[i] == value)
return true;
return false;
}
public bool ContainsStrict(T value)
{
for (int i = 0; i < CSize; i++)
if (mVal[i] === value)
return true;
return false;
}
public int IndexOf(T value)
{
for (int i = 0; i < CSize; i++)
if (mVal[i] == value)
return i;
return -1;
}
public int IndexOfStrict(T value)
{
for (int i = 0; i < CSize; i++)
if (mVal[i] === value)
return i;
return -1;
}
public override void ToString(String strBuffer) mut
{
if (typeof(T) == typeof(char8))

View file

@ -2634,6 +2634,18 @@ namespace System
}
}
public static bool Equals(char8* str1, char8* str2, int length)
{
for (int i < length)
{
char8 c = str1[i];
char8 c2 = str2[i];
if (c != c2)
return false;
}
return true;
}
public RawEnumerator RawChars
{
[Inline]