@@ -31,7 +31,7 @@ static bool clear_combat = false;
3131static bool clear_sparring = true ;
3232static bool clear_hunting = false ;
3333
34- static const int32_t CLEANUP_TICK_INTERVAL = 97 ;
34+ static constexpr int32_t CLEANUP_TICK_INTERVAL = 97 ;
3535
3636static void cleanupLogs ();
3737static 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
168166DFhackCExport command_result plugin_onupdate (color_ostream& out, state_change_event event) {
0 commit comments