Skip to content

Commit 23fb978

Browse files
committed
LibCore: Avoid excessive ref-count churn in event dispatch
We were strongly reffing the event receiver twice before actually invoking the event handlers.
1 parent fa85f62 commit 23fb978

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

Libraries/LibCore/ThreadEventQueue.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,11 @@ size_t ThreadEventQueue::process()
102102
size_t processed_events = 0;
103103
for (size_t i = 0; i < events.size(); ++i) {
104104
auto& queued_event = events.at(i);
105-
auto receiver = queued_event.receiver.strong_ref();
106105
auto& event = *queued_event.event;
107106

108107
if (event.type() == Event::Type::DeferredInvoke) {
109108
static_cast<DeferredInvocationEvent&>(event).m_invokee();
110-
} else if (!receiver) {
111-
// Receiver disappeared, drop the event on the floor.
112-
} else {
113-
NonnullRefPtr<EventReceiver> protector(*receiver);
109+
} else if (auto receiver = queued_event.receiver.strong_ref()) {
114110
receiver->dispatch_event(event);
115111
}
116112
++processed_events;

0 commit comments

Comments
 (0)