performance improvements

This commit is contained in:
Ken Martin 2003-06-24 15:23:34 -04:00
parent 76b344c6fe
commit e315bff47b
3 changed files with 39 additions and 45 deletions

View File

@ -797,19 +797,19 @@ void cmMakefile::AddIncludeDirectory(const char* inc, bool before)
} }
} }
void cmMakefile::AddDefinition(const char* name, const char* value) void cmMakefile::AddDefinition(const char* name, const char* value)
{ {
if (!value ) if (!value )
{ {
return; return;
} }
m_Definitions.erase( DefinitionMap::key_type(name)); m_TemporaryDefinitionKey = name;
m_Definitions.insert(DefinitionMap::value_type(name, value)); m_Definitions[m_TemporaryDefinitionKey] = value;
cmVariableWatch* vv = this->GetVariableWatch(); cmVariableWatch* vv = this->GetVariableWatch();
if ( vv ) if ( vv )
{ {
vv->VariableAccessed(name, cmVariableWatch::VARIABLE_MODIFIED_ACCESS); vv->VariableAccessed(m_TemporaryDefinitionKey,
cmVariableWatch::VARIABLE_MODIFIED_ACCESS);
} }
} }
@ -1034,7 +1034,6 @@ void cmMakefile::AddUtilityCommand(const char* utilityName,
cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname) cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname)
{ {
std::string name = cname; std::string name = cname;
std::string out;
// look through all the source files that have custom commands // look through all the source files that have custom commands
// and see if the custom command has the passed source file as an output // and see if the custom command has the passed source file as an output
@ -1046,7 +1045,7 @@ cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname)
if ((*i)->GetCustomCommand()) if ((*i)->GetCustomCommand())
{ {
// is the output of the custom command match the source files name // is the output of the custom command match the source files name
out = (*i)->GetCustomCommand()->GetOutput(); const std::string &out = (*i)->GetCustomCommand()->GetOutput();
if (out.rfind(name) != out.npos && if (out.rfind(name) != out.npos &&
out.rfind(name) == out.size() - name.size()) out.rfind(name) == out.size() - name.size())
{ {
@ -1432,14 +1431,6 @@ const char *cmMakefile::ExpandVariablesInString(std::string& source,
result += var; result += var;
result += "@"; result += "@";
} }
// do nothing, we remove the variable
/* else
{
result += (markerStartSize == 5 ? "$ENV{" : "${");
result += var;
result += "}";
}
*/
} }
// lookup var, and replace it // lookup var, and replace it
currentPos = endVariablePos+1; currentPos = endVariablePos+1;
@ -1573,10 +1564,12 @@ void cmMakefile::ExpandArguments(
std::vector<std::string>& outArgs) std::vector<std::string>& outArgs)
{ {
std::vector<cmListFileArgument>::const_iterator i; std::vector<cmListFileArgument>::const_iterator i;
std::string value;
outArgs.reserve(inArgs.size());
for(i = inArgs.begin(); i != inArgs.end(); ++i) for(i = inArgs.begin(); i != inArgs.end(); ++i)
{ {
// Expand the variables in the argument. // Expand the variables in the argument.
std::string value = i->Value; value = i->Value;
this->ExpandVariablesInString(value); this->ExpandVariablesInString(value);
// If the argument is quoted, it should be one argument. // If the argument is quoted, it should be one argument.
@ -1678,21 +1671,17 @@ cmSourceFile* cmMakefile::GetSource(const char* sourceName) const
// if the source is provided with a full path use it, otherwise // if the source is provided with a full path use it, otherwise
// by default it is in the current source dir // by default it is in the current source dir
std::string path = cmSystemTools::GetFilenamePath(sourceName); std::string path = cmSystemTools::GetFilenamePath(sourceName);
std::string s = sourceName;
if (path.empty()) if (path.empty())
{ {
s = this->GetCurrentDirectory();
s += "/";
s += cmSystemTools::GetFilenameName(sourceName);
path = this->GetCurrentDirectory(); path = this->GetCurrentDirectory();
} }
std::string sname = std::string sname =
cmSystemTools::GetFilenameWithoutLastExtension(s); cmSystemTools::GetFilenameWithoutLastExtension(sourceName);
// compute the extension // compute the extension
std::string ext; std::string ext
ext = cmSystemTools::GetFilenameLastExtension(s); = cmSystemTools::GetFilenameLastExtension(sourceName);
s = s.substr(0, s.length()-ext.length());
if ( ext.length() && ext[0] == '.' ) if ( ext.length() && ext[0] == '.' )
{ {
ext = ext.substr(1); ext = ext.substr(1);
@ -1715,19 +1704,7 @@ cmSourceFile* cmMakefile::GetSource(const char* sourceName) const
return 0; return 0;
} }
s = this->GetCurrentOutputDirectory();
s += "/";
s += cmSystemTools::GetFilenameName(sourceName);
path = this->GetCurrentOutputDirectory(); path = this->GetCurrentOutputDirectory();
// compute the extension
ext = cmSystemTools::GetFilenameLastExtension(s);
s = s.substr(0, s.length()-ext.length());
if ( ext.length() && ext[0] == '.' )
{
ext = ext.substr(1);
}
for(std::vector<cmSourceFile*>::const_iterator i = m_SourceFiles.begin(); for(std::vector<cmSourceFile*>::const_iterator i = m_SourceFiles.begin();
i != m_SourceFiles.end(); ++i) i != m_SourceFiles.end(); ++i)
{ {

View File

@ -669,6 +669,9 @@ private:
typedef std::map<cmStdString, cmData*> DataMap; typedef std::map<cmStdString, cmData*> DataMap;
DataMap m_DataMap; DataMap m_DataMap;
bool m_Inheriting; bool m_Inheriting;
// used in AddDefinition for performance improvement
DefinitionMap::key_type m_TemporaryDefinitionKey;
}; };

View File

@ -252,23 +252,37 @@ void SystemTools::ReplaceString(kwsys_std::string& source,
const char* replace, const char* replace,
const char* with) const char* with)
{ {
const char *src = source.c_str();
char *searchPos = strstr(src,replace);
// get out quick if string is not found // get out quick if string is not found
kwsys_std::string::size_type start = source.find(replace); if (!searchPos)
if(start == kwsys_std::string::npos)
{ {
return; return;
} }
kwsys_std::string rest;
kwsys_std::string::size_type lengthReplace = strlen(replace); // perform replacements until done
kwsys_std::string::size_type lengthWith = strlen(with); size_t replaceSize = strlen(replace);
while(start != kwsys_std::string::npos) char *orig = strdup(src);
char *currentPos = orig;
searchPos = searchPos - src + orig;
// initialize the result
source.clear();
do
{ {
rest = source.substr(start+lengthReplace); *searchPos = '\0';
source = source.substr(0, start); source += currentPos;
currentPos = searchPos + replaceSize;
// replace
source += with; source += with;
source += rest; searchPos = strstr(currentPos,replace);
start = source.find(replace, start + lengthWith );
} }
while (searchPos);
// copy any trailing text
source += currentPos;
free(orig);
} }
// Read a registry value. // Read a registry value.