Skip to content

Commit

Permalink
VM: use std::erase_if() for VM::sweep()
Browse files Browse the repository at this point in the history
  • Loading branch information
mrunix00 committed Aug 1, 2024
1 parent 4cfc210 commit 2eef162
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ void VM::markAll() {
}
}
void VM::sweep() {
for (auto it = objects.begin(); it != objects.end();) {
if (!(*it)->marked) {
delete *it;
it = objects.erase(it);
std::erase_if(objects, [](Object *obj) {
if (!obj->marked) {
delete obj;
return true;
} else {
(*it)->marked = false;
it++;
obj->marked = false;
return false;
}
}
});
}

void VM::run(const Program &program) {
Expand Down

0 comments on commit 2eef162

Please sign in to comment.