Skip to content

Commit

Permalink
improve: change unregisterCreatureEvent from while to std::erase_if
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas authored Oct 18, 2024
1 parent 1af76e2 commit 1b5cf00
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1628,19 +1628,17 @@ bool Creature::unregisterCreatureEvent(const std::string &name) {

bool resetTypeBit = true;

auto it = eventsList.begin(), end = eventsList.end();
while (it != end) {
const auto curEvent = *it;
std::erase_if(eventsList, [event, type, &resetTypeBit](const auto &curEvent) {
if (curEvent == event) {
it = eventsList.erase(it);
continue;
return true;
}

if (curEvent->getEventType() == type) {
resetTypeBit = false;
}
++it;
}

return false;
});

if (resetTypeBit) {
scriptEventsBitField &= ~(static_cast<uint32_t>(1) << type);
Expand Down

0 comments on commit 1b5cf00

Please sign in to comment.