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

String split optimizations

This commit is contained in:
Brian Fiete 2023-03-01 06:38:09 -05:00
parent 200bb6453c
commit ca3abc617f

View file

@ -3027,7 +3027,8 @@ namespace System
{ {
StringSplitOptions mSplitOptions; StringSplitOptions mSplitOptions;
char8 mFirstSeparator; char8 mFirstSeparator;
char8[] mSeparators; char8* mSeparatorPtr;
int32 mSeparatorCount;
char8* mPtr; char8* mPtr;
int_strsize mStrLen; int_strsize mStrLen;
int32 mCurCount; int32 mCurCount;
@ -3040,10 +3041,17 @@ namespace System
mPtr = ptr; mPtr = ptr;
mStrLen = (int_strsize)strLength; mStrLen = (int_strsize)strLength;
if (separators?.Count > 0) if (separators?.Count > 0)
{
mFirstSeparator = separators[0]; mFirstSeparator = separators[0];
mSeparatorPtr = &separators[0];
mSeparatorCount = (.)separators.Count;
}
else else
mFirstSeparator = '\0'; {
mSeparators = separators; mFirstSeparator = 0;
mSeparatorPtr = null;
mSeparatorCount = 0;
}
mCurCount = 0; mCurCount = 0;
mMaxCount = (int32)count; mMaxCount = (int32)count;
mPos = 0; mPos = 0;
@ -3056,7 +3064,8 @@ namespace System
mPtr = ptr; mPtr = ptr;
mStrLen = (int_strsize)strLength; mStrLen = (int_strsize)strLength;
mFirstSeparator = separator; mFirstSeparator = separator;
mSeparators = null; mSeparatorPtr = null;
mSeparatorCount = 1;
mCurCount = 0; mCurCount = 0;
mMaxCount = (int32)count; mMaxCount = (int32)count;
mPos = 0; mPos = 0;
@ -3103,7 +3112,7 @@ namespace System
return mMatchPos < mStrLen && (!mSplitOptions.HasFlag(StringSplitOptions.RemoveEmptyEntries) || mStrLen != 0); return mMatchPos < mStrLen && (!mSplitOptions.HasFlag(StringSplitOptions.RemoveEmptyEntries) || mStrLen != 0);
} }
} }
public bool MoveNext() mut public bool MoveNext() mut
{ {
if (mCurCount >= mMaxCount) if (mCurCount >= mMaxCount)
@ -3137,18 +3146,39 @@ namespace System
else else
{ {
char8 c = mPtr[mMatchPos]; char8 c = mPtr[mMatchPos];
if (c.IsWhiteSpace && mFirstSeparator == '\0' && (mSeparators == null || mSeparators.IsEmpty)) if (mSeparatorCount == 0)
{ {
foundMatch = true; if (c.IsWhiteSpace)
foundMatch = true;
} }
else if (c == mFirstSeparator) else if (c == mFirstSeparator)
{ {
foundMatch = true; foundMatch = true;
} }
else if (mSeparators != null) else if (mSeparatorCount < 2)
{ {
for (int i = 1; i < mSeparators.Count; i++) continue;
if (c == mSeparators[i]) }
else if (c == mSeparatorPtr[1])
{
foundMatch = true;
}
else if (mSeparatorCount < 3)
{
continue;
}
else if (c == mSeparatorPtr[2])
{
foundMatch = true;
}
else if (mSeparatorCount < 3)
{
continue;
}
else
{
for (int i = 3; i < mSeparatorCount; i++)
if (c == mSeparatorPtr[i])
foundMatch = true; foundMatch = true;
} }
} }