using loop instead of linq

In both of these loops context is captured preventing caching of the lambda. this results in a pretty significant amount of allocations especially with progress bars that constantly are remeasuring
This commit is contained in:
Phil Scott 2021-02-27 00:05:40 -05:00 committed by Patrik Svensson
parent c64884854f
commit bff3438a5a
2 changed files with 14 additions and 2 deletions

View File

@ -8,7 +8,13 @@ namespace Spectre.Console
{
public static int GetCellLength(RenderContext context, string text)
{
return text.Sum(rune => GetCellLength(context, rune));
var sum = 0;
foreach (var rune in text)
{
sum += GetCellLength(context, rune);
}
return sum;
}
public static int GetCellLength(RenderContext context, char rune)

View File

@ -135,7 +135,13 @@ namespace Spectre.Console.Rendering
throw new ArgumentNullException(nameof(segments));
}
return segments.Sum(segment => segment.CellCount(context));
var sum = 0;
foreach (var segment in segments)
{
sum += segment.CellCount(context);
}
return sum;
}
/// <summary>