From af1ac0f685ce1bf4096c52e4943ce9ab2aedf348 Mon Sep 17 00:00:00 2001 From: nanahi <130121847+na-na-hi@users.noreply.github.com> Date: Tue, 11 Mar 2025 18:37:18 -0400 Subject: [PATCH] playloop: only notify MP_EVENT_INPUT_PROCESSED when needed MP_EVENT_INPUT_PROCESSED is used to notify mouse and touch position updates, but it is currently notified for all input commands even when they have nothing to do with mouse position. This results in unnecessary acquisition and comparision of mouse and touch positions for all commands. Optimize this by checking whether the command is marked as requiring the event notification, and only notify if that is true. --- player/playloop.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/player/playloop.c b/player/playloop.c index e4b59dfe69..528d526824 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -108,16 +108,17 @@ void mp_core_unlock(struct MPContext *mpctx) // Process any queued user input. static void mp_process_input(struct MPContext *mpctx) { - int processed = 0; + bool notify = false; for (;;) { mp_cmd_t *cmd = mp_input_read_cmd(mpctx->input); if (!cmd) break; + if (cmd->notify_event) + notify = true; run_command(mpctx, cmd, NULL, NULL, NULL); - processed = 1; } mp_set_timeout(mpctx, mp_input_get_delay(mpctx->input)); - if (processed) + if (notify) mp_notify(mpctx, MP_EVENT_INPUT_PROCESSED, NULL); }