LibCore: Avoid excessive ref-count churn in event dispatch

We were strongly reffing the event receiver twice before actually
invoking the event handlers.
This commit is contained in:
Andreas Kling
2025-12-03 11:10:55 +01:00
committed by Andreas Kling
parent fa85f62895
commit 23fb9781d1
Notes: github-actions[bot] 2025-12-03 12:27:58 +00:00

View File

@@ -102,15 +102,11 @@ size_t ThreadEventQueue::process()
size_t processed_events = 0;
for (size_t i = 0; i < events.size(); ++i) {
auto& queued_event = events.at(i);
auto receiver = queued_event.receiver.strong_ref();
auto& event = *queued_event.event;
if (event.type() == Event::Type::DeferredInvoke) {
static_cast<DeferredInvocationEvent&>(event).m_invokee();
} else if (!receiver) {
// Receiver disappeared, drop the event on the floor.
} else {
NonnullRefPtr<EventReceiver> protector(*receiver);
} else if (auto receiver = queued_event.receiver.strong_ref()) {
receiver->dispatch_event(event);
}
++processed_events;