mirror of
https://github.com/osukey/osukey.git
synced 2025-06-05 21:07:18 +09:00
Apply suggested optimisations
This commit is contained in:
parent
36dd0e6998
commit
1a7937bcf7
@ -100,17 +100,23 @@ namespace osu.Desktop
|
|||||||
|
|
||||||
private static readonly int ellipsis_length = Encoding.UTF8.GetByteCount(new[] { '…' });
|
private static readonly int ellipsis_length = Encoding.UTF8.GetByteCount(new[] { '…' });
|
||||||
|
|
||||||
private string truncate(ReadOnlySpan<char> str)
|
private string truncate(string str)
|
||||||
{
|
{
|
||||||
if (Encoding.UTF8.GetByteCount(str) <= 128)
|
if (Encoding.UTF8.GetByteCount(str) <= 128)
|
||||||
return new string(str);
|
return str;
|
||||||
|
|
||||||
|
ReadOnlyMemory<char> strMem = str.AsMemory();
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
str = str[..^1];
|
strMem = strMem[..^1];
|
||||||
} while (Encoding.UTF8.GetByteCount(str) + ellipsis_length > 128);
|
} while (Encoding.UTF8.GetByteCount(strMem.Span) + ellipsis_length > 128);
|
||||||
|
|
||||||
return new string(str) + '…';
|
return string.Create(strMem.Length + 1, strMem, (span, mem) =>
|
||||||
|
{
|
||||||
|
mem.Span.CopyTo(span);
|
||||||
|
span[^1] = '…';
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private string getDetails(UserActivity activity)
|
private string getDetails(UserActivity activity)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user