Skip to content

Code Quality: HotKey GetModifierCode implementations can be optimized #18316

@KrisVandermotten

Description

@KrisVandermotten

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

  • Better performance (CPU)

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area - actionsFeatures or bug reports relating to actions

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions