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());
return true;
}
// set the value of argc
cmOStringStream argcDefStream;
argcDefStream << expandedArguments.size();
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.
cmListFileFunction newLFF;
// for each function
for(unsigned int c = 0; c < m_Functions.size(); ++c)
{
// 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_FilePath = m_Functions[c].m_FilePath;
newLFF.m_Line = m_Functions[c].m_Line;
// for each argument of the current function
for (std::vector<cmListFileArgument>::const_iterator k =
m_Functions[c].m_Arguments.begin();
k != m_Functions[c].m_Arguments.end(); ++k)
@ -99,34 +109,15 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
cmSystemTools::ReplaceString(tmps, variable.c_str(),
expandedArguments[j-1].c_str());
}
// replace argc, argv arguments
for (unsigned int j = 1; j < m_Args.size(); ++j)
// replace argc
cmSystemTools::ReplaceString(tmps, "${ARGC}",argcDef.c_str());
// repleace ARGN
if (tmps.find("${ARGN}") != std::string::npos)
{
variable = "${ARGC}";
cmSystemTools::ReplaceString(tmps, variable.c_str(),argcDef.c_str());
}
for (unsigned int j = 1; j < m_Args.size(); ++j)
if (!argnDefInitialized)
{
variable = "${ARGV}";
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;
for ( eit = expandedArguments.begin();
eit != expandedArguments.end();
@ -134,23 +125,44 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
{
if ( cnt >= m_Args.size()-1 )
{
if ( var.size() > 0 )
if ( argnDef.size() > 0 )
{
var += ";";
argnDef += ";";
}
var += *eit;
argnDef += *eit;
}
cnt ++;
}
cmSystemTools::ReplaceString(tmps, variable.c_str(),var.c_str());
argnDefInitialized = true;
}
for (unsigned int j = 1; j < m_Args.size(); ++j)
{
// since this could be slow, first check if there is an ARGV
// only then do the inner loop. PS std::string sucks
char argvName[60];
cmSystemTools::ReplaceString(tmps, "${ARGN}", argnDef.c_str());
}
// if the current argument of the current function has ${ARGV in it
// then try replacing ARGV values
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)
{
sprintf(argvName,"${ARGV%i}",t);
@ -158,7 +170,6 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
expandedArguments[t].c_str());
}
}
}
arg.Value = tmps;
arg.Quoted = k->Quoted;