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

Faster Append(char32)

This commit is contained in:
Brian Fiete 2020-03-25 06:26:59 -07:00
parent 2f78063927
commit b5815927ef

View file

@ -857,7 +857,7 @@ namespace System
ptr[mLength++] = c;
}
public void Append(char8 c, int count = 1)
public void Append(char8 c, int count)
{
if (count == 0)
return;
@ -869,11 +869,52 @@ namespace System
ptr[mLength++] = c;
}
public void Append(char32 c, int count = 1)
public void Append(char32 c)
{
let ptr = Ptr;
if (c < (char32)0x80)
{
if (mLength + 1 > AllocSize)
Realloc(CalcNewSize(mLength + 1));
ptr[mLength++] = (char8)c;
}
else if (c < (char32)0x800)
{
if (mLength + 2 > AllocSize)
Realloc(CalcNewSize(mLength + 2));
ptr[mLength++] = (char8)(c>>6) | (char8)0xC0;
ptr[mLength++] = (char8)(c & (char8)0x3F) | (char8)0x80;
}
else if (c < (char32)0x10000)
{
if (mLength + 3 > AllocSize)
Realloc(CalcNewSize(mLength + 3));
ptr[mLength++] = (char8)(c>>12) | (char8)0xE0;
ptr[mLength++] = (char8)((c>>6) & (char8)0x3F) | (char8)0x80;
ptr[mLength++] = (char8)(c & (char8)0x3F) | (char8)0x80;
}
else if (c < (char32)0x110000)
{
if (mLength + 4 > AllocSize)
Realloc(CalcNewSize(mLength + 4));
ptr[mLength++] = (char8)((c>>18) | (char8)0xF0);
ptr[mLength++] = (char8)((c>>12) & (char8)0x3F) | (char8)0x80;
ptr[mLength++] = (char8)((c>>6) & (char8)0x3F) | (char8)0x80;
ptr[mLength++] = (char8)(c & (char8)0x3F) | (char8)0x80;
}
}
public void Append(char32 c, int count)
{
if (count == 0)
return;
if (count == 1)
{
Append(c);
return;
}
int encodedLen = UTF8.GetEncodedLength(c);
if (mLength + count * encodedLen > AllocSize)
@ -907,11 +948,6 @@ namespace System
}
}
/*public void Substring(int idx, int len, String outBuffer)
{
outBuffer.Append(this, idx, len);
}*/
public void EnsureNullTerminator()
{
int allocSize = AllocSize;