Use insert instead of a loop in some cases.

Limit this change to inserting into a vector from a vector.

A follow up change can use insert for inserting into a set.
This commit is contained in:
Stephen Kelly 2014-11-22 11:00:45 +01:00
parent 2f7ef7e38d
commit 238dd2fbab
21 changed files with 48 additions and 169 deletions

View File

@ -1094,11 +1094,8 @@ void cmCTestBuildHandler::ProcessBuffer(const char* data, int length,
{ {
// Create a contiguous array for the line // Create a contiguous array for the line
this->CurrentProcessingLine.clear(); this->CurrentProcessingLine.clear();
t_BuildProcessingQueueType::iterator cit; this->CurrentProcessingLine.insert(this->CurrentProcessingLine.end(),
for ( cit = queue->begin(); cit != it; ++cit ) queue->begin(), queue->end());
{
this->CurrentProcessingLine.push_back(*cit);
}
this->CurrentProcessingLine.push_back(0); this->CurrentProcessingLine.push_back(0);
const char* line = &*this->CurrentProcessingLine.begin(); const char* line = &*this->CurrentProcessingLine.begin();

View File

@ -526,11 +526,8 @@ void cmCTestMultiProcessHandler::CreateParallelTestCostList()
TestList sortedCopy; TestList sortedCopy;
for(TestSet::const_iterator j = currentSet.begin(); sortedCopy.insert(sortedCopy.end(),
j != currentSet.end(); ++j) currentSet.begin(), currentSet.end());
{
sortedCopy.push_back(*j);
}
std::stable_sort(sortedCopy.begin(), sortedCopy.end(), comp); std::stable_sort(sortedCopy.begin(), sortedCopy.end(), comp);

View File

@ -349,11 +349,7 @@ void cmCTestP4::SetP4Options(std::vector<char const*> &CommandOptions)
std::vector<std::string> args = std::vector<std::string> args =
cmSystemTools::ParseArguments(opts.c_str()); cmSystemTools::ParseArguments(opts.c_str());
for(std::vector<std::string>::const_iterator ai = args.begin(); P4Options.insert(P4Options.end(), args.begin(), args.end());
ai != args.end(); ++ai)
{
P4Options.push_back(*ai);
}
} }
CommandOptions.clear(); CommandOptions.clear();

View File

@ -74,13 +74,8 @@ cmCTestGenericHandler* cmCTestSubmitCommand::InitializeHandler()
std::vector<std::string> notesFiles; std::vector<std::string> notesFiles;
cmCTest::VectorOfStrings newNotesFiles; cmCTest::VectorOfStrings newNotesFiles;
cmSystemTools::ExpandListArgument(notesFilesVariable,notesFiles); cmSystemTools::ExpandListArgument(notesFilesVariable,notesFiles);
std::vector<std::string>::iterator it; newNotesFiles.insert(newNotesFiles.end(),
for ( it = notesFiles.begin(); notesFiles.begin(), notesFiles.end());
it != notesFiles.end();
++ it )
{
newNotesFiles.push_back(*it);
}
this->CTest->GenerateNotesFile(newNotesFiles); this->CTest->GenerateNotesFile(newNotesFiles);
} }
@ -91,13 +86,8 @@ cmCTestGenericHandler* cmCTestSubmitCommand::InitializeHandler()
std::vector<std::string> extraFiles; std::vector<std::string> extraFiles;
cmCTest::VectorOfStrings newExtraFiles; cmCTest::VectorOfStrings newExtraFiles;
cmSystemTools::ExpandListArgument(extraFilesVariable,extraFiles); cmSystemTools::ExpandListArgument(extraFilesVariable,extraFiles);
std::vector<std::string>::iterator it; newExtraFiles.insert(newExtraFiles.end(),
for ( it = extraFiles.begin(); extraFiles.begin(), extraFiles.end());
it != extraFiles.end();
++ it )
{
newExtraFiles.push_back(*it);
}
if ( !this->CTest->SubmitExtraFiles(newExtraFiles)) if ( !this->CTest->SubmitExtraFiles(newExtraFiles))
{ {
this->SetError("problem submitting extra files."); this->SetError("problem submitting extra files.");

View File

@ -36,11 +36,7 @@ bool cmAddTestCommand
// Collect the command with arguments. // Collect the command with arguments.
std::vector<std::string> command; std::vector<std::string> command;
for(std::vector<std::string>::const_iterator it = args.begin() + 1; command.insert(command.end(), args.begin() + 1, args.end());
it != args.end(); ++it)
{
command.push_back(*it);
}
// Create the test but add a generator only the first time it is // Create the test but add a generator only the first time it is
// seen. This preserves behavior from before test generators. // seen. This preserves behavior from before test generators.

View File

@ -53,10 +53,7 @@ bool cmConditionEvaluator::IsTrue(
cmArgumentList newArgs; cmArgumentList newArgs;
// copy to the list structure // copy to the list structure
for(unsigned int i = 0; i < args.size(); ++i) newArgs.insert(newArgs.end(), args.begin(), args.end());
{
newArgs.push_back(args[i]);
}
// now loop through the arguments and see if we can reduce any of them // now loop through the arguments and see if we can reduce any of them
// we do this multiple times. Once for each level of precedence // we do this multiple times. Once for each level of precedence
@ -411,10 +408,7 @@ bool cmConditionEvaluator::HandleLevel0(cmArgumentList &newArgs,
// copy to the list structure // copy to the list structure
cmArgumentList::iterator argP1 = arg; cmArgumentList::iterator argP1 = arg;
argP1++; argP1++;
for(; argP1 != argClose; argP1++) newArgs2.insert(newArgs2.end(), argP1, argClose);
{
newArgs2.push_back(*argP1);
}
newArgs2.pop_back(); newArgs2.pop_back();
// now recursively invoke IsTrue to handle the values inside the // now recursively invoke IsTrue to handle the values inside the
// parenthetical expression // parenthetical expression

View File

@ -131,21 +131,14 @@ const char* cmCustomCommand::GetComment() const
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmCustomCommand::AppendCommands(const cmCustomCommandLines& commandLines) void cmCustomCommand::AppendCommands(const cmCustomCommandLines& commandLines)
{ {
for(cmCustomCommandLines::const_iterator i=commandLines.begin(); this->CommandLines.insert(this->CommandLines.end(),
i != commandLines.end(); ++i) commandLines.begin(), commandLines.end());
{
this->CommandLines.push_back(*i);
}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmCustomCommand::AppendDepends(const std::vector<std::string>& depends) void cmCustomCommand::AppendDepends(const std::vector<std::string>& depends)
{ {
for(std::vector<std::string>::const_iterator i=depends.begin(); this->Depends.insert(this->Depends.end(), depends.begin(), depends.end());
i != depends.end(); ++i)
{
this->Depends.push_back(*i);
}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -184,10 +184,8 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
std::vector<std::string> shortArgs = this->Names; std::vector<std::string> shortArgs = this->Names;
this->Names.clear(); // clear out any values in Names this->Names.clear(); // clear out any values in Names
this->Names.push_back(shortArgs[0]); this->Names.push_back(shortArgs[0]);
for(unsigned int j = 1; j < shortArgs.size(); ++j) this->UserGuessArgs.insert(this->UserGuessArgs.end(),
{ shortArgs.begin() + 1, shortArgs.end());
this->UserGuessArgs.push_back(shortArgs[j]);
}
} }
this->ExpandPaths(); this->ExpandPaths();

View File

@ -271,11 +271,7 @@ bool cmFunctionCommand
// create a function blocker // create a function blocker
cmFunctionFunctionBlocker *f = new cmFunctionFunctionBlocker(); cmFunctionFunctionBlocker *f = new cmFunctionFunctionBlocker();
for(std::vector<std::string>::const_iterator j = args.begin(); f->Args.insert(f->Args.end(), args.begin(), args.end());
j != args.end(); ++j)
{
f->Args.push_back(*j);
}
this->Makefile->AddFunctionBlocker(f); this->Makefile->AddFunctionBlocker(f);
return true; return true;
} }

View File

@ -489,11 +489,7 @@ bool cmGeneratorTarget::IsSystemIncludeDirectory(const std::string& dir,
unique.insert(*li); unique.insert(*li);
} }
result.clear(); result.clear();
for(std::set<std::string>::iterator li = unique.begin(); result.insert(result.end(), unique.begin(), unique.end());
li != unique.end(); ++li)
{
result.push_back(*li);
}
IncludeCacheType::value_type entry(config_upper, result); IncludeCacheType::value_type entry(config_upper, result);
iter = this->SystemIncludesCache.insert(entry).first; iter = this->SystemIncludesCache.insert(entry).first;

View File

@ -47,11 +47,8 @@ bool cmInstallFilesCommand
else else
{ {
this->IsFilesForm = false; this->IsFilesForm = false;
std::vector<std::string>::const_iterator s = args.begin(); this->FinalArgs.insert(this->FinalArgs.end(),
for (++s;s != args.end(); ++s) args.begin() + 1, args.end());
{
this->FinalArgs.push_back(*s);
}
} }
this->Makefile->GetLocalGenerator()->GetGlobalGenerator() this->Makefile->GetLocalGenerator()->GetGlobalGenerator()

View File

@ -27,11 +27,7 @@ bool cmInstallProgramsCommand
this->Destination = args[0]; this->Destination = args[0];
std::vector<std::string>::const_iterator s = args.begin(); this->FinalArgs.insert(this->FinalArgs.end(), args.begin() + 1, args.end());
for (++s;s != args.end(); ++s)
{
this->FinalArgs.push_back(*s);
}
this->Makefile->GetLocalGenerator()->GetGlobalGenerator() this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->AddInstallComponent(this->Makefile->GetSafeDefinition( ->AddInstallComponent(this->Makefile->GetSafeDefinition(

View File

@ -634,11 +634,7 @@ void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
// Parse the string to get the custom command line. // Parse the string to get the custom command line.
cmCustomCommandLine commandLine; cmCustomCommandLine commandLine;
std::vector<std::string> cmd = cmSystemTools::ParseArguments(i->c_str()); std::vector<std::string> cmd = cmSystemTools::ParseArguments(i->c_str());
for(std::vector<std::string>::iterator a = cmd.begin(); commandLine.insert(commandLine.end(), cmd.begin(), cmd.end());
a != cmd.end(); ++a)
{
commandLine.push_back(*a);
}
// Store this command line. // Store this command line.
commandLines.push_back(commandLine); commandLines.push_back(commandLine);
@ -745,11 +741,7 @@ void cmLocalGenerator::AddBuildTargetRule(const std::string& llang,
// Parse the string to get the custom command line. // Parse the string to get the custom command line.
cmCustomCommandLine commandLine; cmCustomCommandLine commandLine;
std::vector<std::string> cmd = cmSystemTools::ParseArguments(i->c_str()); std::vector<std::string> cmd = cmSystemTools::ParseArguments(i->c_str());
for(std::vector<std::string>::iterator a = cmd.begin(); commandLine.insert(commandLine.end(), cmd.begin(), cmd.end());
a != cmd.end(); ++a)
{
commandLine.push_back(*a);
}
// Store this command line. // Store this command line.
commandLines.push_back(commandLine); commandLines.push_back(commandLine);

View File

@ -1856,13 +1856,8 @@ void cmLocalUnixMakefileGenerator3
{ {
text = "Running external command ..."; text = "Running external command ...";
} }
std::set<std::string>::const_iterator dit; depends.insert(depends.end(), glIt->second.GetUtilities().begin(),
for ( dit = glIt->second.GetUtilities().begin(); glIt->second.GetUtilities().end());
dit != glIt->second.GetUtilities().end();
++ dit )
{
depends.push_back(*dit);
}
this->AppendEcho(commands, text, this->AppendEcho(commands, text,
cmLocalUnixMakefileGenerator3::EchoGlobal); cmLocalUnixMakefileGenerator3::EchoGlobal);

View File

@ -328,11 +328,7 @@ bool cmMacroCommand::InitialPass(std::vector<std::string> const& args,
// create a function blocker // create a function blocker
cmMacroFunctionBlocker *f = new cmMacroFunctionBlocker(); cmMacroFunctionBlocker *f = new cmMacroFunctionBlocker();
for(std::vector<std::string>::const_iterator j = args.begin(); f->Args.insert(f->Args.end(), args.begin(), args.end());
j != args.end(); ++j)
{
f->Args.push_back(*j);
}
this->Makefile->AddFunctionBlocker(f); this->Makefile->AddFunctionBlocker(f);
return true; return true;
} }

View File

@ -2567,12 +2567,7 @@ std::vector<std::string> cmMakefile
} }
std::vector<std::string> res; std::vector<std::string> res;
res.insert(res.end(), definitions.begin(), definitions.end());
std::set<std::string>::iterator fit;
for ( fit = definitions.begin(); fit != definitions.end(); fit ++ )
{
res.push_back(*fit);
}
return res; return res;
} }

View File

@ -759,13 +759,10 @@ cmMakefileTargetGenerator
if(const char* extra_outputs_str = if(const char* extra_outputs_str =
source.GetProperty("OBJECT_OUTPUTS")) source.GetProperty("OBJECT_OUTPUTS"))
{ {
// Register these as extra files to clean.
cmSystemTools::ExpandListArgument(extra_outputs_str, outputs); cmSystemTools::ExpandListArgument(extra_outputs_str, outputs);
for(std::vector<std::string>::const_iterator eoi = outputs.begin()+1; this->CleanFiles.insert(this->CleanFiles.end(),
eoi != outputs.end(); ++eoi) outputs.begin() + 1, outputs.end());
{
// Register this as an extra file to clean.
this->CleanFiles.push_back(*eoi);
}
} }
// Write the rule. // Write the rule.
@ -1174,11 +1171,7 @@ cmMakefileTargetGenerator
{ {
cmCustomCommandGenerator ccg(*cc, this->ConfigName, this->Makefile); cmCustomCommandGenerator ccg(*cc, this->ConfigName, this->Makefile);
const std::vector<std::string>& outputs = ccg.GetOutputs(); const std::vector<std::string>& outputs = ccg.GetOutputs();
for(std::vector<std::string>::const_iterator o = outputs.begin(); depends.insert(depends.end(), outputs.begin(), outputs.end());
o != outputs.end(); ++o)
{
depends.push_back(*o);
}
} }
} }
} }
@ -1462,11 +1455,8 @@ void cmMakefileTargetGenerator::WriteTargetDriverRule(
} }
// Make sure the extra files are built. // Make sure the extra files are built.
for(std::set<std::string>::const_iterator i = this->ExtraFiles.begin(); depends.insert(depends.end(),
i != this->ExtraFiles.end(); ++i) this->ExtraFiles.begin(), this->ExtraFiles.end());
{
depends.push_back(*i);
}
} }
// Write the driver rule. // Write the driver rule.
@ -1553,11 +1543,7 @@ void cmMakefileTargetGenerator
if(cmComputeLinkInformation* cli = this->Target->GetLinkInformation(cfg)) if(cmComputeLinkInformation* cli = this->Target->GetLinkInformation(cfg))
{ {
std::vector<std::string> const& libDeps = cli->GetDepends(); std::vector<std::string> const& libDeps = cli->GetDepends();
for(std::vector<std::string>::const_iterator j = libDeps.begin(); depends.insert(depends.end(), libDeps.begin(), libDeps.end());
j != libDeps.end(); ++j)
{
depends.push_back(*j);
}
} }
} }
@ -1577,12 +1563,8 @@ void cmMakefileTargetGenerator
} }
// Add dependencies on the external object files. // Add dependencies on the external object files.
for(std::vector<std::string>::const_iterator obj depends.insert(depends.end(),
= this->ExternalObjects.begin(); this->ExternalObjects.begin(), this->ExternalObjects.end());
obj != this->ExternalObjects.end(); ++obj)
{
depends.push_back(*obj);
}
// Add a dependency on the rule file itself. // Add a dependency on the rule file itself.
this->LocalGenerator->AppendRuleDepend(depends, this->LocalGenerator->AppendRuleDepend(depends,

View File

@ -2188,24 +2188,12 @@ bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile,
std::vector<std::string> command; std::vector<std::string> command;
command.push_back(this->MocExecutable); command.push_back(this->MocExecutable);
for (std::list<std::string>::const_iterator it = this->MocIncludes.begin(); command.insert(command.end(),
it != this->MocIncludes.end(); this->MocIncludes.begin(), this->MocIncludes.end());
++it) command.insert(command.end(),
{ this->MocDefinitions.begin(), this->MocDefinitions.end());
command.push_back(*it); command.insert(command.end(),
} this->MocOptions.begin(), this->MocOptions.end());
for(std::list<std::string>::const_iterator it=this->MocDefinitions.begin();
it != this->MocDefinitions.end();
++it)
{
command.push_back(*it);
}
for(std::vector<std::string>::const_iterator it=this->MocOptions.begin();
it != this->MocOptions.end();
++it)
{
command.push_back(*it);
}
#ifdef _WIN32 #ifdef _WIN32
command.push_back("-DWIN32"); command.push_back("-DWIN32");
#endif #endif
@ -2277,12 +2265,7 @@ bool cmQtAutoGenerators::GenerateUi(const std::string& realName,
cmSystemTools::ExpandListArgument(optionIt->second, fileOpts); cmSystemTools::ExpandListArgument(optionIt->second, fileOpts);
this->MergeUicOptions(opts, fileOpts, this->QtMajorVersion == "5"); this->MergeUicOptions(opts, fileOpts, this->QtMajorVersion == "5");
} }
for(std::vector<std::string>::const_iterator optIt = opts.begin(); command.insert(command.end(), opts.begin(), opts.end());
optIt != opts.end();
++optIt)
{
command.push_back(*optIt);
}
command.push_back("-o"); command.push_back("-o");
command.push_back(this->Builddir + ui_output_file); command.push_back(this->Builddir + ui_output_file);

View File

@ -39,10 +39,7 @@ bool cmRemoveCommand
// check for REMOVE(VAR v1 v2 ... vn) // check for REMOVE(VAR v1 v2 ... vn)
std::vector<std::string> argsExpanded; std::vector<std::string> argsExpanded;
std::vector<std::string> temp; std::vector<std::string> temp;
for(unsigned int j = 1; j < args.size(); ++j) temp.insert(temp.end(), args.begin() + 1, args.end());
{
temp.push_back(args[j]);
}
cmSystemTools::ExpandList(temp, argsExpanded); cmSystemTools::ExpandList(temp, argsExpanded);
// now create the new value // now create the new value

View File

@ -1273,11 +1273,7 @@ bool cmSystemTools::Split(const char* s, std::vector<std::string>& l)
{ {
std::vector<std::string> temp; std::vector<std::string> temp;
bool res = Superclass::Split(s, temp); bool res = Superclass::Split(s, temp);
for(std::vector<std::string>::const_iterator i = temp.begin(); l.insert(l.end(), temp.begin(), temp.end());
i != temp.end(); ++i)
{
l.push_back(*i);
}
return res; return res;
} }

View File

@ -6449,11 +6449,8 @@ cmTargetInternals::ComputeLinkImplementationLanguages(
// Get languages used in our source files. // Get languages used in our source files.
thisTarget->GetLanguages(languages, config); thisTarget->GetLanguages(languages, config);
// Copy the set of langauges to the link implementation. // Copy the set of langauges to the link implementation.
for(std::set<std::string>::iterator li = languages.begin(); impl.Languages.insert(impl.Languages.begin(),
li != languages.end(); ++li) languages.begin(), languages.end());
{
impl.Languages.push_back(*li);
}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------