Commit f8642f95 authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'reduce-string-copying'

2c2bb5f5 Remove unnecessary operator<< usage
1e4e2f99 Remove unused variables
25486156 Improved checking for number of arguments passed
86dc86dd Add const-reference qualifications
76bdb407

 Change std::basic_string<char> to std::string
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !886
parents f9ea6247 2c2bb5f5
......@@ -24,7 +24,7 @@ bool cmAddCustomTargetCommand::InitialPass(
return false;
}
std::string targetName = args[0];
std::string const& targetName = args[0];
// Check the target name.
if (targetName.find_first_of("/\\") != targetName.npos) {
......
......@@ -19,7 +19,7 @@ bool cmAddDependenciesCommand::InitialPass(
return false;
}
std::string target_name = args[0];
std::string const& target_name = args[0];
if (this->Makefile->IsAlias(target_name)) {
std::ostringstream e;
e << "Cannot add target-level dependencies to alias target \""
......
......@@ -24,7 +24,7 @@ bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args,
}
std::vector<std::string>::const_iterator s = args.begin();
std::string exename = *s;
std::string const& exename = *s;
++s;
bool use_win32 = false;
......
......@@ -37,7 +37,7 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args,
std::vector<std::string>::const_iterator s = args.begin();
std::string libName = *s;
std::string const& libName = *s;
++s;
......
......@@ -20,7 +20,7 @@ bool cmAddSubDirectoryCommand::InitialPass(
}
// store the binpath
std::string srcArg = args[0];
std::string const& srcArg = args[0];
std::string binArg;
bool excludeFromAll = false;
......
......@@ -18,13 +18,13 @@ class cmExecutionStatus;
bool cmAuxSourceDirectoryCommand::InitialPass(
std::vector<std::string> const& args, cmExecutionStatus&)
{
if (args.size() < 2 || args.size() > 2) {
if (args.size() != 2) {
this->SetError("called with incorrect number of arguments");
return false;
}
std::string sourceListValue;
std::string templateDirectory = args[0];
std::string const& templateDirectory = args[0];
std::string tdir;
if (!cmSystemTools::FileIsFullPath(templateDirectory.c_str())) {
tdir = this->Makefile->GetCurrentSourceDirectory();
......@@ -54,7 +54,7 @@ bool cmAuxSourceDirectoryCommand::InitialPass(
std::string ext = file.substr(dotpos + 1);
std::string base = file.substr(0, dotpos);
// Process only source files
std::vector<std::string> srcExts =
std::vector<std::string> const& srcExts =
this->Makefile->GetCMakeInstance()->GetSourceExtensions();
if (!base.empty() &&
std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end()) {
......
......@@ -32,7 +32,7 @@ bool cmBuildCommand::MainSignature(std::vector<std::string> const& args)
}
// The cmake variable in which to store the result.
const char* variable = args[0].c_str();
std::string const& variable = args[0];
// Parse remaining arguments.
std::string configuration;
......@@ -104,7 +104,7 @@ bool cmBuildCommand::TwoArgsSignature(std::vector<std::string> const& args)
return false;
}
const char* define = args[0].c_str();
std::string const& define = args[0];
const char* cacheValue = this->Makefile->GetDefinition(define);
std::string configType;
......
......@@ -26,7 +26,7 @@ bool cmCMakeHostSystemInformationCommand::InitialPass(
return false;
}
std::string variable = args[current_index + 1];
std::string const& variable = args[current_index + 1];
current_index += 2;
if (args.size() < (current_index + 2) || args[current_index] != "QUERY") {
......@@ -41,7 +41,7 @@ bool cmCMakeHostSystemInformationCommand::InitialPass(
std::string result_list;
for (size_t i = current_index + 1; i < args.size(); ++i) {
std::string key = args[i];
std::string const& key = args[i];
if (i != current_index + 1) {
result_list += ";";
}
......
......@@ -19,7 +19,7 @@ bool cmConfigureFileCommand::InitialPass(std::vector<std::string> const& args,
return false;
}
const char* inFile = args[0].c_str();
std::string const& inFile = args[0];
if (!cmSystemTools::FileIsFullPath(inFile)) {
this->InputFile = this->Makefile->GetCurrentSourceDirectory();
this->InputFile += "/";
......@@ -38,7 +38,7 @@ bool cmConfigureFileCommand::InitialPass(std::vector<std::string> const& args,
return false;
}
const char* outFile = args[1].c_str();
std::string const& outFile = args[1];
if (!cmSystemTools::FileIsFullPath(outFile)) {
this->OutputFile = this->Makefile->GetCurrentBinaryDirectory();
this->OutputFile += "/";
......
......@@ -20,23 +20,25 @@ bool cmDefinePropertyCommand::InitialPass(std::vector<std::string> const& args,
// Get the scope in which to define the property.
cmProperty::ScopeType scope;
if (args[0] == "GLOBAL") {
std::string const& scope_arg = args[0];
if (scope_arg == "GLOBAL") {
scope = cmProperty::GLOBAL;
} else if (args[0] == "DIRECTORY") {
} else if (scope_arg == "DIRECTORY") {
scope = cmProperty::DIRECTORY;
} else if (args[0] == "TARGET") {
} else if (scope_arg == "TARGET") {
scope = cmProperty::TARGET;
} else if (args[0] == "SOURCE") {
} else if (scope_arg == "SOURCE") {
scope = cmProperty::SOURCE_FILE;
} else if (args[0] == "TEST") {
} else if (scope_arg == "TEST") {
scope = cmProperty::TEST;
} else if (args[0] == "VARIABLE") {
} else if (scope_arg == "VARIABLE") {
scope = cmProperty::VARIABLE;
} else if (args[0] == "CACHED_VARIABLE") {
} else if (scope_arg == "CACHED_VARIABLE") {
scope = cmProperty::CACHED_VARIABLE;
} else {
std::ostringstream e;
e << "given invalid scope " << args[0] << ". "
e << "given invalid scope " << scope_arg << ". "
<< "Valid scopes are "
<< "GLOBAL, DIRECTORY, TARGET, SOURCE, "
<< "TEST, VARIABLE, CACHED_VARIABLE.";
......
......@@ -353,7 +353,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
all_files_map_t allFiles;
std::vector<std::string> cFiles;
std::vector<std::string> srcExts =
std::vector<std::string> const& srcExts =
this->GlobalGenerator->GetCMakeInstance()->GetSourceExtensions();
for (std::vector<cmLocalGenerator*>::const_iterator lg = lgs.begin();
......@@ -387,7 +387,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
bool isCFile = false;
std::string lang = (*si)->GetLanguage();
if (lang == "C" || lang == "CXX") {
std::string srcext = (*si)->GetExtension();
std::string const& srcext = (*si)->GetExtension();
for (std::vector<std::string>::const_iterator ext =
srcExts.begin();
ext != srcExts.end(); ++ext) {
......@@ -398,7 +398,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
}
}
std::string fullPath = (*si)->GetFullPath();
std::string const& fullPath = (*si)->GetFullPath();
if (isCFile) {
cFiles.push_back(fullPath);
......@@ -414,7 +414,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
}
}
std::vector<std::string> headerExts =
std::vector<std::string> const& headerExts =
this->GlobalGenerator->GetCMakeInstance()->GetHeaderExtensions();
// The following loop tries to add header files matching to implementation
......
......@@ -240,7 +240,7 @@ std::string cmExtraCodeLiteGenerator::CollectSourceFiles(
bool isCFile = false;
std::string lang = (*si)->GetLanguage();
if (lang == "C" || lang == "CXX") {
std::string srcext = (*si)->GetExtension();
std::string const& srcext = (*si)->GetExtension();
for (std::vector<std::string>::const_iterator ext = srcExts.begin();
ext != srcExts.end(); ++ext) {
if (srcext == *ext) {
......@@ -600,9 +600,6 @@ void cmExtraCodeLiteGenerator::CreateNewProjectFile(
// which may have an acompanying header, one for all other files
std::string projectType;
std::vector<std::string> headerExts =
this->GlobalGenerator->GetCMakeInstance()->GetHeaderExtensions();
std::map<std::string, cmSourceFile*> cFiles;
std::set<std::string> otherFiles;
......
......@@ -453,7 +453,7 @@ void cmExtraEclipseCDT4Generator::WriteGroups(
for (std::vector<const cmSourceFile*>::const_iterator fileIt =
sFiles.begin();
fileIt != sFiles.end(); ++fileIt) {
std::string fullPath = (*fileIt)->GetFullPath();
std::string const& fullPath = (*fileIt)->GetFullPath();
if (!cmSystemTools::FileIsDirectory(fullPath)) {
std::string linkName4 = linkName3;
......@@ -508,7 +508,7 @@ void cmExtraEclipseCDT4Generator::CreateLinksForTargets(cmXMLWriter& xml)
for (std::vector<cmSourceFile*>::const_iterator sfIt = files.begin();
sfIt != files.end(); sfIt++) {
// Add the file to the list of sources.
std::string source = (*sfIt)->GetFullPath();
std::string const& source = (*sfIt)->GetFullPath();
cmSourceGroup* sourceGroup =
makefile->FindSourceGroup(source.c_str(), sourceGroups);
sourceGroup->AssignSource(*sfIt);
......
......@@ -110,7 +110,7 @@ bool cmFileCommand::InitialPass(std::vector<std::string> const& args,
this->SetError("must be called with at least two arguments.");
return false;
}
std::string subCommand = args[0];
std::string const& subCommand = args[0];
if (subCommand == "WRITE") {
return this->HandleWriteCommand(args, false);
}
......
......@@ -938,7 +938,7 @@ bool cmFindPackageCommand::FindConfig()
bool cmFindPackageCommand::FindPrefixedConfig()
{
std::vector<std::string>& prefixes = this->SearchPaths;
std::vector<std::string> const& prefixes = this->SearchPaths;
for (std::vector<std::string>::const_iterator pi = prefixes.begin();
pi != prefixes.end(); ++pi) {
if (this->SearchPrefix(*pi)) {
......@@ -950,7 +950,7 @@ bool cmFindPackageCommand::FindPrefixedConfig()
bool cmFindPackageCommand::FindFrameworkConfig()
{
std::vector<std::string>& prefixes = this->SearchPaths;
std::vector<std::string> const& prefixes = this->SearchPaths;
for (std::vector<std::string>::const_iterator i = prefixes.begin();
i != prefixes.end(); ++i) {
if (this->SearchFrameworkPrefix(*i)) {
......@@ -962,7 +962,7 @@ bool cmFindPackageCommand::FindFrameworkConfig()
bool cmFindPackageCommand::FindAppBundleConfig()
{
std::vector<std::string>& prefixes = this->SearchPaths;
std::vector<std::string> const& prefixes = this->SearchPaths;
for (std::vector<std::string>::const_iterator i = prefixes.begin();
i != prefixes.end(); ++i) {
if (this->SearchAppBundlePrefix(*i)) {
......
......@@ -20,7 +20,7 @@ bool cmGetCMakePropertyCommand::InitialPass(
return false;
}
std::string variable = args[0];
std::string const& variable = args[0];
std::string output = "NOTFOUND";
if (args[1] == "VARIABLES") {
......
......@@ -20,7 +20,7 @@ bool cmGetDirectoryPropertyCommand::InitialPass(
}
std::vector<std::string>::const_iterator i = args.begin();
std::string variable = *i;
std::string const& variable = *i;
++i;
// get the directory argument if there is one
......
......@@ -15,8 +15,8 @@ bool cmGetSourceFilePropertyCommand::InitialPass(
this->SetError("called with incorrect number of arguments");
return false;
}
const char* var = args[0].c_str();
const char* file = args[1].c_str();
std::string const& var = args[0];
std::string const& file = args[1];
cmSourceFile* sf = this->Makefile->GetSource(file);
// for the location we must create a source file first
......
......@@ -22,8 +22,8 @@ bool cmGetTargetPropertyCommand::InitialPass(
this->SetError("called with incorrect number of arguments");
return false;
}
std::string var = args[0];
const std::string& targetName = args[1];
std::string const& var = args[0];
std::string const& targetName = args[1];
std::string prop;
bool prop_exists = false;
......
......@@ -16,8 +16,8 @@ bool cmGetTestPropertyCommand::InitialPass(
return false;
}
std::string testName = args[0];
std::string var = args[2];
std::string const& testName = args[0];
std::string const& var = args[2];
cmTest* test = this->Makefile->GetTest(testName);
if (test) {
const char* prop = CM_NULLPTR;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment