Use erase-remove idiom for dead-variable removal.

Change-Id: Ief9aa9aa035424573533072af2c0cd8cee5bf9b4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314460
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2020-09-01 11:15:29 -04:00 committed by Skia Commit-Bot
parent 7954d6c77c
commit 4202dc47a4

View File

@ -1671,14 +1671,13 @@ bool Compiler::optimize(Program& program) {
for (auto iter = program.fElements.begin(); iter != program.fElements.end();) {
if ((*iter)->fKind == ProgramElement::kVar_Kind) {
VarDeclarations& vars = (*iter)->as<VarDeclarations>();
for (auto varIter = vars.fVars.begin(); varIter != vars.fVars.end();) {
const Variable& var = *(*varIter)->as<VarDeclaration>().fVar;
if (var.dead()) {
varIter = vars.fVars.erase(varIter);
} else {
++varIter;
}
}
vars.fVars.erase(
std::remove_if(vars.fVars.begin(), vars.fVars.end(),
[](const std::unique_ptr<Statement>& stmt) {
return stmt->as<VarDeclaration>().fVar->dead();
}),
vars.fVars.end());
if (vars.fVars.size() == 0) {
iter = program.fElements.erase(iter);
continue;