ENH: make it run much faster

This commit is contained in:
Bill Hoffman 2004-05-19 16:04:48 -04:00
parent 6b31e5c851
commit f82c1bfc8d
1 changed files with 56 additions and 45 deletions

View File

@ -71,12 +71,21 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
cmSystemTools::Error(error.str().c_str()); cmSystemTools::Error(error.str().c_str());
return true; return true;
} }
// set the value of argc
cmOStringStream argcDefStream; cmOStringStream argcDefStream;
argcDefStream << expandedArguments.size(); argcDefStream << expandedArguments.size();
std::string argcDef = argcDefStream.str(); std::string argcDef = argcDefStream.str();
// declare varuiables for ARGV ARGN but do not compute until needed
std::string argvDef;
std::string argnDef;
bool argnDefInitialized = false;
bool argvDefInitialized = false;
// Invoke all the functions that were collected in the block. // Invoke all the functions that were collected in the block.
cmListFileFunction newLFF; cmListFileFunction newLFF;
// for each function
for(unsigned int c = 0; c < m_Functions.size(); ++c) for(unsigned int c = 0; c < m_Functions.size(); ++c)
{ {
// Replace the formal arguments and then invoke the command. // Replace the formal arguments and then invoke the command.
@ -85,6 +94,7 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
newLFF.m_Name = m_Functions[c].m_Name; newLFF.m_Name = m_Functions[c].m_Name;
newLFF.m_FilePath = m_Functions[c].m_FilePath; newLFF.m_FilePath = m_Functions[c].m_FilePath;
newLFF.m_Line = m_Functions[c].m_Line; newLFF.m_Line = m_Functions[c].m_Line;
// for each argument of the current function
for (std::vector<cmListFileArgument>::const_iterator k = for (std::vector<cmListFileArgument>::const_iterator k =
m_Functions[c].m_Arguments.begin(); m_Functions[c].m_Arguments.begin();
k != m_Functions[c].m_Arguments.end(); ++k) k != m_Functions[c].m_Arguments.end(); ++k)
@ -99,34 +109,15 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
cmSystemTools::ReplaceString(tmps, variable.c_str(), cmSystemTools::ReplaceString(tmps, variable.c_str(),
expandedArguments[j-1].c_str()); expandedArguments[j-1].c_str());
} }
// replace argc, argv arguments // replace argc
for (unsigned int j = 1; j < m_Args.size(); ++j) cmSystemTools::ReplaceString(tmps, "${ARGC}",argcDef.c_str());
// repleace ARGN
if (tmps.find("${ARGN}") != std::string::npos)
{ {
variable = "${ARGC}"; if (!argnDefInitialized)
cmSystemTools::ReplaceString(tmps, variable.c_str(),argcDef.c_str());
}
for (unsigned int j = 1; j < m_Args.size(); ++j)
{ {
variable = "${ARGV}";
std::vector<std::string>::iterator eit; std::vector<std::string>::iterator eit;
std::string var = "";
for ( eit = expandedArguments.begin();
eit != expandedArguments.end();
++ eit )
{
if ( var.size() > 0 )
{
var += ";";
}
var += *eit;
}
cmSystemTools::ReplaceString(tmps, variable.c_str(),var.c_str());
}
for (unsigned int j = 1; j < m_Args.size(); ++j)
{
variable = "${ARGN}";
std::vector<std::string>::iterator eit;
std::string var = "";
std::vector<std::string>::size_type cnt = 0; std::vector<std::string>::size_type cnt = 0;
for ( eit = expandedArguments.begin(); for ( eit = expandedArguments.begin();
eit != expandedArguments.end(); eit != expandedArguments.end();
@ -134,23 +125,44 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
{ {
if ( cnt >= m_Args.size()-1 ) if ( cnt >= m_Args.size()-1 )
{ {
if ( var.size() > 0 ) if ( argnDef.size() > 0 )
{ {
var += ";"; argnDef += ";";
} }
var += *eit; argnDef += *eit;
} }
cnt ++; cnt ++;
} }
cmSystemTools::ReplaceString(tmps, variable.c_str(),var.c_str()); argnDefInitialized = true;
} }
for (unsigned int j = 1; j < m_Args.size(); ++j) cmSystemTools::ReplaceString(tmps, "${ARGN}", argnDef.c_str());
{ }
// since this could be slow, first check if there is an ARGV
// only then do the inner loop. PS std::string sucks // if the current argument of the current function has ${ARGV in it
char argvName[60]; // then try replacing ARGV values
if (tmps.find("${ARGV") != std::string::npos) if (tmps.find("${ARGV") != std::string::npos)
{ {
char argvName[60];
// repleace ARGV, compute it only once
if (!argvDefInitialized)
{
std::vector<std::string>::iterator eit;
for ( eit = expandedArguments.begin();
eit != expandedArguments.end();
++ eit )
{
if ( argvDef.size() > 0 )
{
argvDef += ";";
}
argvDef += *eit;
}
argvDefInitialized = true;
}
cmSystemTools::ReplaceString(tmps, "${ARGV}", argvDef.c_str());
// also replace the ARGV1 ARGV2 ... etc
for (unsigned int t = 0; t < expandedArguments.size(); ++t) for (unsigned int t = 0; t < expandedArguments.size(); ++t)
{ {
sprintf(argvName,"${ARGV%i}",t); sprintf(argvName,"${ARGV%i}",t);
@ -158,7 +170,6 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
expandedArguments[t].c_str()); expandedArguments[t].c_str());
} }
} }
}
arg.Value = tmps; arg.Value = tmps;
arg.Quoted = k->Quoted; arg.Quoted = k->Quoted;