Skip to content

Commit c011d31

Browse files
committed
constExpr. erase_if
1 parent d786dea commit c011d31

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

plugins/logcleaner/logcleaner.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static bool clear_combat = false;
3131
static bool clear_sparring = true;
3232
static bool clear_hunting = false;
3333

34-
static const int32_t CLEANUP_TICK_INTERVAL = 97;
34+
static constexpr int32_t CLEANUP_TICK_INTERVAL = 97;
3535

3636
static void cleanupLogs();
3737
static command_result do_command(color_ostream& out, std::vector<std::string>& params);
@@ -130,6 +130,9 @@ static void cleanupLogs() {
130130
if (!is_enabled || !world)
131131
return;
132132

133+
if (!clear_combat && !clear_sparring && !clear_hunting)
134+
return;
135+
133136
// Collect all report IDs from unit combat/sparring/hunting logs
134137
std::unordered_set<int32_t> report_ids_to_remove;
135138
bool log_types[] = {clear_combat, clear_sparring, clear_hunting};
@@ -152,17 +155,12 @@ static void cleanupLogs() {
152155
// Remove collected reports from global buffers
153156
auto& reports = world->status.reports;
154157

155-
for (auto report_id : report_ids_to_remove) {
156-
df::report* report = df::report::find(report_id);
157-
if (!report)
158-
continue;
159-
160-
auto it = std::find(reports.begin(), reports.end(), report);
161-
if (it != reports.end()) {
162-
delete report;
163-
reports.erase(it);
164-
}
165-
}
158+
std::erase_if(reports, [&](df::report* report) {
159+
if (!report || !report_ids_to_remove.contains(report->id))
160+
return false;
161+
delete report;
162+
return true;
163+
});
166164
}
167165

168166
DFhackCExport command_result plugin_onupdate(color_ostream& out, state_change_event event) {

0 commit comments

Comments
 (0)