cmListCommand: Avoid needlessly erasing from vectors.

The entire vector will be destroyed at once at the end of the scope,
and the remove algorithms already give us the end of the range of
interesting values, so just use those sentinals.
This commit is contained in:
Stephen Kelly 2015-02-15 15:48:51 +01:00
parent 1c7c35c372
commit 116459d34f
1 changed files with 19 additions and 15 deletions

View File

@ -357,13 +357,14 @@ bool cmListCommand
std::vector<std::string> remove(args.begin() + 2, args.end());
std::sort(remove.begin(), remove.end());
remove.erase(std::unique(remove.begin(), remove.end()), remove.end());
std::vector<std::string>::const_iterator remEnd =
std::unique(remove.begin(), remove.end());
std::vector<std::string>::const_iterator remBegin = remove.begin();
varArgsExpanded.erase(
cmRemoveMatching(varArgsExpanded, remove),
varArgsExpanded.end());
std::string value = cmJoin(varArgsExpanded, ";");
std::vector<std::string>::const_iterator argsEnd =
cmRemoveMatching(varArgsExpanded, cmRange(remBegin, remEnd));
std::vector<std::string>::const_iterator argsBegin = varArgsExpanded.begin();
std::string value = cmJoin(cmRange(argsBegin, argsEnd), ";");
this->Makefile->AddDefinition(listName, value.c_str());
return true;
}
@ -418,9 +419,11 @@ bool cmListCommand
return false;
}
varArgsExpanded.erase(cmRemoveDuplicates(varArgsExpanded),
varArgsExpanded.end());
std::string value = cmJoin(varArgsExpanded, ";");
std::vector<std::string>::const_iterator argsEnd =
cmRemoveDuplicates(varArgsExpanded);
std::vector<std::string>::const_iterator argsBegin =
varArgsExpanded.begin();
std::string value = cmJoin(cmRange(argsBegin, argsEnd), ";");
this->Makefile->AddDefinition(listName, value.c_str());
return true;
@ -503,13 +506,14 @@ bool cmListCommand::HandleRemoveAtCommand(
}
std::sort(removed.begin(), removed.end());
removed.erase(std::unique(removed.begin(), removed.end()), removed.end());
varArgsExpanded.erase(cmRemoveIndices(varArgsExpanded, removed),
varArgsExpanded.end());
std::string value = cmJoin(varArgsExpanded, ";");
std::vector<size_t>::const_iterator remEnd =
std::unique(removed.begin(), removed.end());
std::vector<size_t>::const_iterator remBegin = removed.begin();
std::vector<std::string>::const_iterator argsEnd =
cmRemoveIndices(varArgsExpanded, cmRange(remBegin, remEnd));
std::vector<std::string>::const_iterator argsBegin = varArgsExpanded.begin();
std::string value = cmJoin(cmRange(argsBegin, argsEnd), ";");
this->Makefile->AddDefinition(listName, value.c_str());
return true;