mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-24 04:02:50 +08:00
Adds rune width caching for cell length calculations
This commit is contained in:
parent
fe5096dceb
commit
36ec3d1fd3
@ -4,11 +4,14 @@ namespace Spectre.Console
|
|||||||
{
|
{
|
||||||
internal static class Cell
|
internal static class Cell
|
||||||
{
|
{
|
||||||
|
private static readonly int?[] _runeWidthCache = new int?[char.MaxValue];
|
||||||
|
|
||||||
public static int GetCellLength(string text)
|
public static int GetCellLength(string text)
|
||||||
{
|
{
|
||||||
var sum = 0;
|
var sum = 0;
|
||||||
foreach (var rune in text)
|
for (var index = 0; index < text.Length; index++)
|
||||||
{
|
{
|
||||||
|
var rune = text[index];
|
||||||
sum += GetCellLength(rune);
|
sum += GetCellLength(rune);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,7 +31,7 @@ namespace Spectre.Console
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return UnicodeCalculator.GetWidth(rune);
|
return _runeWidthCache[rune] ??= UnicodeCalculator.GetWidth(rune);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user