From 6f6473d6a40a5deb5e95499545c90a865fbc711f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 4 Sep 2021 17:46:57 +0200 Subject: [PATCH] SystemMonitor: Use HashMap::ensure() in ProcessModel::update() --- Userland/Applications/SystemMonitor/ProcessModel.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Userland/Applications/SystemMonitor/ProcessModel.cpp b/Userland/Applications/SystemMonitor/ProcessModel.cpp index 43ceef87e6..c253a9adb4 100644 --- a/Userland/Applications/SystemMonitor/ProcessModel.cpp +++ b/Userland/Applications/SystemMonitor/ProcessModel.cpp @@ -369,15 +369,9 @@ void ProcessModel::update() state.state = thread.state; sum_time_scheduled += thread.time_user + thread.time_kernel; sum_time_scheduled_kernel += thread.time_kernel; - { - auto pit = m_threads.find(thread.tid); - if (pit == m_threads.end()) - m_threads.set(thread.tid, make()); - } - auto pit = m_threads.find(thread.tid); - VERIFY(pit != m_threads.end()); - (*pit).value->previous_state = (*pit).value->current_state; - (*pit).value->current_state = state; + auto& thread_data = *m_threads.ensure(thread.tid, [] { return make(); }); + thread_data.previous_state = move(thread_data.current_state); + thread_data.current_state = move(state); live_tids.set(thread.tid); }