mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-15 12:45:01 +00:00
perf: Replacing recursion with loop
This commit is contained in:
@@ -101,26 +101,18 @@ namespace ICD.Common.Utils.Extensions
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static IEnumerable<string> SplitIterator(string value, char delimeter, int count)
|
private static IEnumerable<string> SplitIterator(string value, char delimeter, int count)
|
||||||
{
|
{
|
||||||
if (count < 2)
|
while (count > 1)
|
||||||
{
|
{
|
||||||
yield return value;
|
int index = value.IndexOf(delimeter);
|
||||||
yield break;
|
if (index < 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
yield return value.Substring(0, index);
|
||||||
|
value = value.Substring(index + 1);
|
||||||
|
count--;
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = value.IndexOf(delimeter);
|
yield return value;
|
||||||
if (index < 0)
|
|
||||||
{
|
|
||||||
yield return value;
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
|
|
||||||
string first = value.Substring(0, index);
|
|
||||||
string second = value.Substring(index + 1);
|
|
||||||
count--;
|
|
||||||
|
|
||||||
yield return first;
|
|
||||||
foreach (string item in second.Split(delimeter, count))
|
|
||||||
yield return item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user