1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 08:32:57 +08:00

Apply suggested optimisations

This commit is contained in:
smoogipoo 2019-12-25 12:04:28 +09:00
parent 36dd0e6998
commit 1a7937bcf7

View File

@ -100,17 +100,23 @@ namespace osu.Desktop
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)
return new string(str);
return str;
ReadOnlyMemory<char> strMem = str.AsMemory();
do
{
str = str[..^1];
} while (Encoding.UTF8.GetByteCount(str) + ellipsis_length > 128);
strMem = strMem[..^1];
} 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)