Optimize report deletion

develop
Ryan Williams 2022-06-07 04:21:48 -07:00 committed by GitHub
parent 5d08e5ae67
commit a7267e3c4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 6 deletions

@ -1415,15 +1415,19 @@ static bool recent_report_any(df::unit *unit)
static void delete_old_reports() static void delete_old_reports()
{ {
auto &reports = world->status.reports; auto &reports = world->status.reports;
while (reports.size() > MAX_REPORTS_SIZE) if (reports.size() > MAX_REPORTS_SIZE)
{ {
if (reports[0] != NULL) size_t excess = reports.size() - MAX_REPORTS_SIZE;
for (size_t i = 0; i < excess; i++)
{ {
if (reports[0]->flags.bits.announcement) if (reports[i] != NULL)
erase_from_vector(world->status.announcements, &df::report::id, reports[0]->id); { // report destructor
delete reports[0]; if (reports[i]->flags.bits.announcement)
erase_from_vector(world->status.announcements, &df::report::id, reports[i]->id);
delete reports[i];
}
} }
reports.erase(reports.begin()); reports.erase(reports.begin(), reports.begin() + excess);
} }
} }