Skip to content

Commit

Permalink
Proc::draw() -> Use std::erase_if() instead of for loops
Browse files Browse the repository at this point in the history
  • Loading branch information
aristocratos committed Dec 28, 2023
1 parent 2fba934 commit 285fb21
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/btop_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1799,7 +1799,7 @@ namespace Proc {
p_counters[p.pid] = 0;
}
else if (p.cpu_p < 0.1 and ++p_counters[p.pid] >= 10) {
p_graphs.erase(p.pid);
if (p_graphs.contains(p.pid)) p_graphs.erase(p.pid);
p_counters.erase(p.pid);
}
else
Expand Down Expand Up @@ -1927,22 +1927,18 @@ namespace Proc {
//? Clear out left over graphs from dead processes at a regular interval
if (not data_same and ++counter >= 100) {
counter = 0;
for (auto element = p_graphs.begin(); element != p_graphs.end();) {
if (rng::find(plist, element->first, &proc_info::pid) == plist.end()) {
element = p_graphs.erase(element);
p_counters.erase(element->first);
}
else
++element;
}

for (auto element = p_wide_cmd.begin(); element != p_wide_cmd.end();) {
if (rng::find(plist, element->first, &proc_info::pid) == plist.end()) {
element = p_wide_cmd.erase(element);
}
else
++element;
}
std::erase_if(p_graphs, [&](const auto& pair) {
return rng::find(plist, pair.first, &proc_info::pid) == plist.end();
});

std::erase_if(p_counters, [&](const auto& pair) {
return rng::find(plist, pair.first, &proc_info::pid) == plist.end();
});

std::erase_if(p_wide_cmd, [&](const auto& pair) {
return rng::find(plist, pair.first, &proc_info::pid) == plist.end();
});
}

if (selected == 0 and selected_pid != 0) {
Expand Down

0 comments on commit 285fb21

Please sign in to comment.