cmMacroCommand: Compute variables outside of two loops.

Avoid computing them from scratch for each argument of each
function.
This commit is contained in:
Stephen Kelly 2015-02-11 19:51:15 +01:00
parent 8e0827b646
commit f79c0f7697
1 changed files with 12 additions and 6 deletions

View File

@ -115,6 +115,15 @@ bool cmMacroHelperCommand::InvokeInitialPass
= expandedArgs.begin() + (this->Args.size() - 1); = expandedArgs.begin() + (this->Args.size() - 1);
std::string expandedArgn = cmJoin(cmRange(eit, expandedArgs.end()), ";"); std::string expandedArgn = cmJoin(cmRange(eit, expandedArgs.end()), ";");
std::string expandedArgv = cmJoin(expandedArgs, ";"); std::string expandedArgv = cmJoin(expandedArgs, ";");
std::vector<std::string> variables;
variables.reserve(this->Args.size() - 1);
for (unsigned int j = 1; j < this->Args.size(); ++j)
{
std::string variable = "${";
variable += this->Args[j];
variable += "}";
variables.push_back(variable);
}
if(!this->Functions.empty()) if(!this->Functions.empty())
{ {
this->FilePath = this->Functions[0].FilePath; this->FilePath = this->Functions[0].FilePath;
@ -147,13 +156,10 @@ bool cmMacroHelperCommand::InvokeInitialPass
{ {
tmps = k->Value; tmps = k->Value;
// replace formal arguments // replace formal arguments
for (unsigned int j = 1; j < this->Args.size(); ++j) for (unsigned int j = 0; j < variables.size(); ++j)
{ {
variable = "${"; cmSystemTools::ReplaceString(tmps, variables[j].c_str(),
variable += this->Args[j]; expandedArgs[j].c_str());
variable += "}";
cmSystemTools::ReplaceString(tmps, variable.c_str(),
expandedArgs[j-1].c_str());
} }
// replace argc // replace argc
cmSystemTools::ReplaceString(tmps, "${ARGC}",argcDef.c_str()); cmSystemTools::ReplaceString(tmps, "${ARGC}",argcDef.c_str());