From e315bff47b144764bc9202b707c82d48298bab25 Mon Sep 17 00:00:00 2001 From: Ken Martin Date: Tue, 24 Jun 2003 15:23:34 -0400 Subject: performance improvements --- Source/cmMakefile.cxx | 47 +++++++++++--------------------------------- Source/cmMakefile.h | 3 +++ Source/kwsys/SystemTools.cxx | 36 ++++++++++++++++++++++----------- 3 files changed, 40 insertions(+), 46 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index c271ccc..03db683 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -797,19 +797,19 @@ void cmMakefile::AddIncludeDirectory(const char* inc, bool before) } } - void cmMakefile::AddDefinition(const char* name, const char* value) { if (!value ) { return; } - m_Definitions.erase( DefinitionMap::key_type(name)); - m_Definitions.insert(DefinitionMap::value_type(name, value)); + m_TemporaryDefinitionKey = name; + m_Definitions[m_TemporaryDefinitionKey] = value; cmVariableWatch* vv = this->GetVariableWatch(); 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) { std::string name = cname; - std::string out; // look through all the source files that have custom commands // 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()) { // 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 && out.rfind(name) == out.size() - name.size()) { @@ -1432,14 +1431,6 @@ const char *cmMakefile::ExpandVariablesInString(std::string& source, result += var; result += "@"; } - // do nothing, we remove the variable -/* else - { - result += (markerStartSize == 5 ? "$ENV{" : "${"); - result += var; - result += "}"; - } -*/ } // lookup var, and replace it currentPos = endVariablePos+1; @@ -1573,10 +1564,12 @@ void cmMakefile::ExpandArguments( std::vector& outArgs) { std::vector::const_iterator i; + std::string value; + outArgs.reserve(inArgs.size()); for(i = inArgs.begin(); i != inArgs.end(); ++i) { // Expand the variables in the argument. - std::string value = i->Value; + value = i->Value; this->ExpandVariablesInString(value); // 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 // by default it is in the current source dir std::string path = cmSystemTools::GetFilenamePath(sourceName); - std::string s = sourceName; if (path.empty()) { - s = this->GetCurrentDirectory(); - s += "/"; - s += cmSystemTools::GetFilenameName(sourceName); path = this->GetCurrentDirectory(); } + std::string sname = - cmSystemTools::GetFilenameWithoutLastExtension(s); + cmSystemTools::GetFilenameWithoutLastExtension(sourceName); // compute the extension - std::string ext; - ext = cmSystemTools::GetFilenameLastExtension(s); - s = s.substr(0, s.length()-ext.length()); + std::string ext + = cmSystemTools::GetFilenameLastExtension(sourceName); if ( ext.length() && ext[0] == '.' ) { ext = ext.substr(1); @@ -1715,19 +1704,7 @@ cmSourceFile* cmMakefile::GetSource(const char* sourceName) const return 0; } - s = this->GetCurrentOutputDirectory(); - s += "/"; - s += cmSystemTools::GetFilenameName(sourceName); 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::const_iterator i = m_SourceFiles.begin(); i != m_SourceFiles.end(); ++i) { diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index f2965aa..19e712a 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -669,6 +669,9 @@ private: typedef std::map DataMap; DataMap m_DataMap; bool m_Inheriting; + + // used in AddDefinition for performance improvement + DefinitionMap::key_type m_TemporaryDefinitionKey; }; diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 70d0d96..0b887fc 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -252,23 +252,37 @@ void SystemTools::ReplaceString(kwsys_std::string& source, const char* replace, const char* with) { + const char *src = source.c_str(); + char *searchPos = strstr(src,replace); + // get out quick if string is not found - kwsys_std::string::size_type start = source.find(replace); - if(start == kwsys_std::string::npos) + if (!searchPos) { return; } - kwsys_std::string rest; - kwsys_std::string::size_type lengthReplace = strlen(replace); - kwsys_std::string::size_type lengthWith = strlen(with); - while(start != kwsys_std::string::npos) - { - rest = source.substr(start+lengthReplace); - source = source.substr(0, start); + + // perform replacements until done + size_t replaceSize = strlen(replace); + char *orig = strdup(src); + char *currentPos = orig; + searchPos = searchPos - src + orig; + + // initialize the result + source.clear(); + do + { + *searchPos = '\0'; + source += currentPos; + currentPos = searchPos + replaceSize; + // replace source += with; - source += rest; - start = source.find(replace, start + lengthWith ); + searchPos = strstr(currentPos,replace); } + while (searchPos); + + // copy any trailing text + source += currentPos; + free(orig); } // Read a registry value. -- cgit v0.12