mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 17:02:51 +08:00
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:
parent
c64884854f
commit
bff3438a5a
@ -8,7 +8,13 @@ namespace Spectre.Console
|
|||||||
{
|
{
|
||||||
public static int GetCellLength(RenderContext context, string text)
|
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)
|
public static int GetCellLength(RenderContext context, char rune)
|
||||||
|
@ -135,7 +135,13 @@ namespace Spectre.Console.Rendering
|
|||||||
throw new ArgumentNullException(nameof(segments));
|
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>
|
/// <summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user