From fa9bd171103e03bccc2113ccb112c703eb79c4c2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 4 Sep 2024 15:34:29 +0900 Subject: [PATCH] Fix alloc overhead in hot path for keyboard checks --- osu.Framework/Input/Bindings/KeyCombination.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/osu.Framework/Input/Bindings/KeyCombination.cs b/osu.Framework/Input/Bindings/KeyCombination.cs index 4a178fd253..f2024456f9 100644 --- a/osu.Framework/Input/Bindings/KeyCombination.cs +++ b/osu.Framework/Input/Bindings/KeyCombination.cs @@ -207,7 +207,14 @@ internal static bool IsPressed(ImmutableArray pressedPhysicalKeys, Inp return pressedPhysicalKeys.Contains(candidateKey); Debug.Assert(candidateKey.IsVirtual()); - return pressedPhysicalKeys.Any(k => getVirtualKey(k) == candidateKey); + + foreach (var pk in pressedPhysicalKeys) + { + if (getVirtualKey(pk) == candidateKey) + return true; + } + + return false; } public bool Equals(KeyCombination other) => Keys.SequenceEqual(other.Keys);