mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-15 06:44:10 +02:00
Faster Append(char32)
This commit is contained in:
parent
2f78063927
commit
b5815927ef
1 changed files with 43 additions and 7 deletions
|
@ -857,7 +857,7 @@ namespace System
|
||||||
ptr[mLength++] = c;
|
ptr[mLength++] = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Append(char8 c, int count = 1)
|
public void Append(char8 c, int count)
|
||||||
{
|
{
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -869,11 +869,52 @@ namespace System
|
||||||
ptr[mLength++] = c;
|
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)
|
if (count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (count == 1)
|
||||||
|
{
|
||||||
|
Append(c);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int encodedLen = UTF8.GetEncodedLength(c);
|
int encodedLen = UTF8.GetEncodedLength(c);
|
||||||
|
|
||||||
if (mLength + count * encodedLen > AllocSize)
|
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()
|
public void EnsureNullTerminator()
|
||||||
{
|
{
|
||||||
int allocSize = AllocSize;
|
int allocSize = AllocSize;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue