mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-12 05:14:10 +02:00
Corlib helper methods
This commit is contained in:
parent
6eddf12948
commit
74b73e5dc8
5 changed files with 116 additions and 2 deletions
|
@ -363,6 +363,44 @@ namespace System
|
||||||
return .(this);
|
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()
|
protected override void GCMarkMembers()
|
||||||
{
|
{
|
||||||
let type = typeof(T);
|
let type = typeof(T);
|
||||||
|
|
|
@ -551,6 +551,14 @@ namespace System.Collections
|
||||||
mSize = (.)size;
|
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()
|
public Enumerator GetEnumerator()
|
||||||
{
|
{
|
||||||
return Enumerator(this);
|
return Enumerator(this);
|
||||||
|
@ -636,6 +644,19 @@ namespace System.Collections
|
||||||
return -1;
|
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)
|
public void Insert(int index, T item)
|
||||||
{
|
{
|
||||||
var item; // This creates a copy - required if item is a ref to an element
|
var item; // This creates a copy - required if item is a ref to an element
|
||||||
|
|
|
@ -292,6 +292,13 @@ namespace System
|
||||||
Runtime.FatalError("Assert failed");
|
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_SetReturnType(int32 typeId);
|
||||||
static extern void* Comptime_MethodBuilder_EmitStr(void* native, StringView str);
|
static extern void* Comptime_MethodBuilder_EmitStr(void* native, StringView str);
|
||||||
static extern void* Comptime_CreateMethod(int32 typeId, StringView methodName, Type returnType, MethodFlags methodFlags);
|
static extern void* Comptime_CreateMethod(int32 typeId, StringView methodName, Type returnType, MethodFlags methodFlags);
|
||||||
|
|
|
@ -15,8 +15,6 @@ namespace System
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public explicit static operator T[CSize] (Self val)
|
public explicit static operator T[CSize] (Self val)
|
||||||
{
|
{
|
||||||
return val.mVal;
|
return val.mVal;
|
||||||
|
@ -28,6 +26,44 @@ namespace System
|
||||||
return .(&val.mVal, CSize);
|
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
|
public override void ToString(String strBuffer) mut
|
||||||
{
|
{
|
||||||
if (typeof(T) == typeof(char8))
|
if (typeof(T) == typeof(char8))
|
||||||
|
|
|
@ -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
|
public RawEnumerator RawChars
|
||||||
{
|
{
|
||||||
[Inline]
|
[Inline]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue