Description
HotKey.LocalizedLabel uses a local function GetModifierCode to calculate a localized string representation of the HotKey's modifiers.
It's a frequently called method. During startup alone, it's called 55 times on my test machine. Moreover, LocalizedLabel is called whenever the HotKey is displayed, e.g. when a local menu is opened.
That means the function should be efficient. Unfortunately, the builder.Remove(0, 1) call at the end is relatively expensive. Luckily, is can be avoided easily, if we append the + at the end of every modifier string instead of at the beginning.
While we're at it, we should also fix the GetModifierCode local function in RawLabel, which has the same problem. We should also append string constants there, instead of enum values which require an expensive runtime ToString call.
Concerned code
- src\Files.App\Data\Commands\HotKey\HotKey.cs
Gains
Requirements
- refactor the
GetModifierCode local functions
Comments
I'll make a PR. It's simple and straightforward. The effect won't be enormous, but everything helps.
Description
HotKey.LocalizedLabeluses a local functionGetModifierCodeto calculate a localized string representation of the HotKey's modifiers.It's a frequently called method. During startup alone, it's called 55 times on my test machine. Moreover,
LocalizedLabelis called whenever the HotKey is displayed, e.g. when a local menu is opened.That means the function should be efficient. Unfortunately, the
builder.Remove(0, 1)call at the end is relatively expensive. Luckily, is can be avoided easily, if we append the+at the end of every modifier string instead of at the beginning.While we're at it, we should also fix the
GetModifierCodelocal function inRawLabel, which has the same problem. We should also append string constants there, instead of enum values which require an expensive runtimeToStringcall.Concerned code
Gains
Requirements
GetModifierCodelocal functionsComments
I'll make a PR. It's simple and straightforward. The effect won't be enormous, but everything helps.