From dd36942508aee46ff0b0357daed108f293260924 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Sat, 9 Mar 2024 13:58:05 +0300 Subject: [PATCH 1/3] Reduce allocations in DrawableFlag tooltip --- osu.Game/Users/Drawables/DrawableFlag.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osu.Game/Users/Drawables/DrawableFlag.cs b/osu.Game/Users/Drawables/DrawableFlag.cs index 289f68ee7f..08c323d42c 100644 --- a/osu.Game/Users/Drawables/DrawableFlag.cs +++ b/osu.Game/Users/Drawables/DrawableFlag.cs @@ -15,11 +15,14 @@ namespace osu.Game.Users.Drawables { private readonly CountryCode countryCode; - public LocalisableString TooltipText => countryCode == CountryCode.Unknown ? string.Empty : countryCode.GetDescription(); + public LocalisableString TooltipText => countryCode == CountryCode.Unknown ? string.Empty : description; + + private readonly string description; public DrawableFlag(CountryCode countryCode) { this.countryCode = countryCode; + description = countryCode.GetDescription(); } [BackgroundDependencyLoader] From 58b6acde10eee69faedd57fcf5c6f1869eb8fba7 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Sat, 9 Mar 2024 14:10:32 +0300 Subject: [PATCH 2/3] Further simplify tooltip text creation --- osu.Game/Users/Drawables/DrawableFlag.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Users/Drawables/DrawableFlag.cs b/osu.Game/Users/Drawables/DrawableFlag.cs index 08c323d42c..39f0ab370b 100644 --- a/osu.Game/Users/Drawables/DrawableFlag.cs +++ b/osu.Game/Users/Drawables/DrawableFlag.cs @@ -15,14 +15,14 @@ namespace osu.Game.Users.Drawables { private readonly CountryCode countryCode; - public LocalisableString TooltipText => countryCode == CountryCode.Unknown ? string.Empty : description; + public LocalisableString TooltipText => tooltipText; - private readonly string description; + private readonly string tooltipText; public DrawableFlag(CountryCode countryCode) { this.countryCode = countryCode; - description = countryCode.GetDescription(); + tooltipText = countryCode == CountryCode.Unknown ? string.Empty : countryCode.GetDescription(); } [BackgroundDependencyLoader] From b8a362fcb69390fb774bcb5a4afc78bb138ddf7e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sat, 9 Mar 2024 20:17:27 +0800 Subject: [PATCH 3/3] Simplify assignment by using an auto property --- osu.Game/Users/Drawables/DrawableFlag.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/osu.Game/Users/Drawables/DrawableFlag.cs b/osu.Game/Users/Drawables/DrawableFlag.cs index 39f0ab370b..6813b13cef 100644 --- a/osu.Game/Users/Drawables/DrawableFlag.cs +++ b/osu.Game/Users/Drawables/DrawableFlag.cs @@ -15,14 +15,12 @@ namespace osu.Game.Users.Drawables { private readonly CountryCode countryCode; - public LocalisableString TooltipText => tooltipText; - - private readonly string tooltipText; + public LocalisableString TooltipText { get; } public DrawableFlag(CountryCode countryCode) { this.countryCode = countryCode; - tooltipText = countryCode == CountryCode.Unknown ? string.Empty : countryCode.GetDescription(); + TooltipText = countryCode == CountryCode.Unknown ? string.Empty : countryCode.GetDescription(); } [BackgroundDependencyLoader]