From f79c0f7697ee0bd25ec74f7dbb2ac0cf6189a9df Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 11 Feb 2015 19:51:15 +0100 Subject: cmMacroCommand: Compute variables outside of two loops. Avoid computing them from scratch for each argument of each function. --- Source/cmMacroCommand.cxx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index 8bbb7c6..8424c75 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -115,6 +115,15 @@ bool cmMacroHelperCommand::InvokeInitialPass = expandedArgs.begin() + (this->Args.size() - 1); std::string expandedArgn = cmJoin(cmRange(eit, expandedArgs.end()), ";"); std::string expandedArgv = cmJoin(expandedArgs, ";"); + std::vector variables; + variables.reserve(this->Args.size() - 1); + for (unsigned int j = 1; j < this->Args.size(); ++j) + { + std::string variable = "${"; + variable += this->Args[j]; + variable += "}"; + variables.push_back(variable); + } if(!this->Functions.empty()) { this->FilePath = this->Functions[0].FilePath; @@ -147,13 +156,10 @@ bool cmMacroHelperCommand::InvokeInitialPass { tmps = k->Value; // replace formal arguments - for (unsigned int j = 1; j < this->Args.size(); ++j) + for (unsigned int j = 0; j < variables.size(); ++j) { - variable = "${"; - variable += this->Args[j]; - variable += "}"; - cmSystemTools::ReplaceString(tmps, variable.c_str(), - expandedArgs[j-1].c_str()); + cmSystemTools::ReplaceString(tmps, variables[j].c_str(), + expandedArgs[j].c_str()); } // replace argc cmSystemTools::ReplaceString(tmps, "${ARGC}",argcDef.c_str()); -- cgit v0.12