Skip to content

Commit

Permalink
Remove allocation overhead in button propagation flow
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Jan 11, 2024
1 parent 631577e commit 94b4b24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions osu.Framework/Input/Bindings/KeyBindingContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ private bool handleNewPressed(InputState state, InputKey newKey, Vector2? scroll

bool handled = false;
var bindings = KeyBindings?.Except(pressedBindings) ?? Enumerable.Empty<IKeyBinding>();

var newlyPressed = bindings.Where(m =>
m.KeyCombination.IsPressed(pressedCombination, matchingMode));

Expand Down
11 changes: 10 additions & 1 deletion osu.Framework/Input/ButtonEventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,16 @@ private void handleButtonUp(InputState state)
/// <returns>The drawable which handled the event or null if none.</returns>
protected Drawable? PropagateButtonEvent(IEnumerable<Drawable> drawables, UIEvent e)
{
var handledBy = drawables.FirstOrDefault(target => target.TriggerEvent(e));
Drawable? handledBy = null;

foreach (Drawable target in drawables)
{
if (target.TriggerEvent(e))
{
handledBy = target;
break;
}
}

if (handledBy != null)
Logger.Log($"{e} handled by {handledBy}.", LoggingTarget.Runtime, LogLevel.Debug);
Expand Down

0 comments on commit 94b4b24

Please sign in to comment.