cmMacroCommand: Manipulate target string directly.

Avoid copying a string from the source, manipulating it, and then
copying it back.  Manipulate it in place instead.
This commit is contained in:
Stephen Kelly 2015-02-11 22:16:03 +01:00
parent 83414d5a07
commit b5f98e5012

View File

@ -151,37 +151,33 @@ bool cmMacroHelperCommand::InvokeInitialPass
k->FilePath = this->FilePath.c_str(); k->FilePath = this->FilePath.c_str();
cmListFileArgument arg; cmListFileArgument arg;
if(k->Delim == cmListFileArgument::Bracket)
{
arg.Value = k->Value; arg.Value = k->Value;
} if(k->Delim != cmListFileArgument::Bracket)
else
{ {
std::string tmps = k->Value;
// replace formal arguments // replace formal arguments
for (unsigned int j = 0; j < variables.size(); ++j) for (unsigned int j = 0; j < variables.size(); ++j)
{ {
cmSystemTools::ReplaceString(tmps, variables[j].c_str(), cmSystemTools::ReplaceString(arg.Value, variables[j].c_str(),
expandedArgs[j].c_str()); expandedArgs[j].c_str());
} }
// replace argc // replace argc
cmSystemTools::ReplaceString(tmps, "${ARGC}",argcDef.c_str()); cmSystemTools::ReplaceString(arg.Value, "${ARGC}",argcDef.c_str());
cmSystemTools::ReplaceString(tmps, "${ARGN}", expandedArgn.c_str()); cmSystemTools::ReplaceString(arg.Value, "${ARGN}",
cmSystemTools::ReplaceString(tmps, "${ARGV}", expandedArgv.c_str()); expandedArgn.c_str());
cmSystemTools::ReplaceString(arg.Value, "${ARGV}",
expandedArgv.c_str());
// if the current argument of the current function has ${ARGV in it // if the current argument of the current function has ${ARGV in it
// then try replacing ARGV values // then try replacing ARGV values
if (tmps.find("${ARGV") != std::string::npos) if (arg.Value.find("${ARGV") != std::string::npos)
{ {
for (unsigned int t = 0; t < expandedArgs.size(); ++t) for (unsigned int t = 0; t < expandedArgs.size(); ++t)
{ {
cmSystemTools::ReplaceString(tmps, argVs[t].c_str(), cmSystemTools::ReplaceString(arg.Value, argVs[t].c_str(),
expandedArgs[t].c_str()); expandedArgs[t].c_str());
} }
} }
arg.Value = tmps;
} }
arg.Delim = k->Delim; arg.Delim = k->Delim;
arg.FilePath = k->FilePath; arg.FilePath = k->FilePath;