Merge topic 'use-algorithms'

d8639733 cmSystemTools: Remove unnecessary comparison.
803317aa cmSystemTools: Early return if size makes later comparison false.
11093a03 Replace temporary bool by inlining warning condition.
6cd2ee95 Replace loop with member algorithm.
94e993a0 cmComputeLinkDepends: Remove temporary iterator copy.
69dbe51b Replace loop with algorithm.
683fafea Replace a loop with std::transform.
63f584b6 Replace while loop with member insert.
74c4d9d2 Take a size check outside of an inner loop.
71d47115 Use insert member instead of back_inserter.
39622c99 Convert while loop to member insert.
a7fcc148 Convert loop to algorithm.
d46c4f07 Extract a prefix variable from loop.
d59913f0 Take computation out of loop.
3f3db744 cmMakefile: Remove ExpandSourceListArguments.
bd990c80 Remove use of ExpandSourceListArguments.
...
This commit is contained in:
Brad King 2015-02-10 09:37:57 -05:00 committed by CMake Topic Stage
commit e2619c13f7
24 changed files with 74 additions and 147 deletions

View File

@ -26,7 +26,7 @@
int main(int argc, char* argv[])
{
//if ( cmsys::SystemTools::FileExists(
cmsys_stl::string cwd = cmsys::SystemTools::GetCurrentWorkingDirectory();
std::string cwd = cmsys::SystemTools::GetCurrentWorkingDirectory();
cmsys::ofstream ofs("/tmp/output.txt");
CFStringRef fileName;
@ -66,7 +66,7 @@ int main(int argc, char* argv[])
//dispose of the CF variable
CFRelease(scriptFileURL);
cmsys_stl::string fullScriptPath = reinterpret_cast<char*>(path);
std::string fullScriptPath = reinterpret_cast<char*>(path);
delete [] path;
@ -75,10 +75,10 @@ int main(int argc, char* argv[])
return 1;
}
cmsys_stl::string scriptDirectory = cmsys::SystemTools::GetFilenamePath(
std::string scriptDirectory = cmsys::SystemTools::GetFilenamePath(
fullScriptPath);
ofs << fullScriptPath.c_str() << cmsys_ios::endl;
cmsys_stl::vector<const char*> args;
std::vector<const char*> args;
args.push_back(fullScriptPath.c_str());
int cc;
for ( cc = 1; cc < argc; ++ cc )

View File

@ -654,7 +654,7 @@ bool cmCPackNSISGenerator::GetListOfSubdirectories(const char* topdir,
if (strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),".") &&
strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),".."))
{
cmsys_stl::string fullPath = topdir;
std::string fullPath = topdir;
fullPath += "/";
fullPath += dir.GetFile(static_cast<unsigned long>(fileNum));
if(cmsys::SystemTools::FileIsDirectory(fullPath) &&

View File

@ -2542,10 +2542,10 @@ bool cmCTestCoverageHandler::IntersectsFilter(LabelSet const& labels)
}
std::vector<int> ids;
cmsys_stl::set_intersection
std::set_intersection
(labels.begin(), labels.end(),
this->LabelFilter.begin(), this->LabelFilter.end(),
cmsys_stl::back_inserter(ids));
std::back_inserter(ids));
return !ids.empty();
}

View File

@ -149,10 +149,10 @@ int main(int argc, char** argv)
QStringList args = app.arguments();
if(args.count() == 2)
{
cmsys_stl::string filePath = cmSystemTools::CollapseFullPath(args[1].toLocal8Bit().data());
std::string filePath = cmSystemTools::CollapseFullPath(args[1].toLocal8Bit().data());
// check if argument is a directory containing CMakeCache.txt
cmsys_stl::string buildFilePath =
std::string buildFilePath =
cmSystemTools::CollapseFullPath("CMakeCache.txt", filePath.c_str());
// check if argument is a CMakeCache.txt file
@ -163,7 +163,7 @@ int main(int argc, char** argv)
}
// check if argument is a directory containing CMakeLists.txt
cmsys_stl::string srcFilePath =
std::string srcFilePath =
cmSystemTools::CollapseFullPath("CMakeLists.txt", filePath.c_str());
if(cmSystemTools::FileExists(buildFilePath.c_str()))

View File

@ -435,11 +435,7 @@ bool cmAddLibraryCommand
cmSystemTools::Message(msg.c_str() ,"Warning");
}
while (s != args.end())
{
srclists.push_back(*s);
++s;
}
srclists.insert(srclists.end(), s, args.end());
this->Makefile->AddLibrary(libName, type, srclists, excludeFromAll);

View File

@ -438,15 +438,14 @@ void CCONV cmExpandSourceListArguments(void *arg,
char ***resArgv,
unsigned int startArgumentIndex)
{
cmMakefile *mf = static_cast<cmMakefile *>(arg);
(void)arg;
(void)startArgumentIndex;
std::vector<std::string> result;
std::vector<std::string> args2;
int i;
for (i = 0; i < numArgs; ++i)
{
args2.push_back(args[i]);
result.push_back(args[i]);
}
mf->ExpandSourceListArguments(args2, result, startArgumentIndex);
int resargc = static_cast<int>(result.size());
char **resargv = 0;
if (resargc)

View File

@ -669,7 +669,7 @@ void cmComputeLinkDepends::InferDependencies()
for(++i; i != sets->end(); ++i)
{
DependSet intersection;
cmsys_stl::set_intersection
std::set_intersection
(common.begin(), common.end(), i->begin(), i->end(),
std::inserter(intersection, intersection.begin()));
common = intersection;
@ -689,11 +689,10 @@ void cmComputeLinkDepends::CleanConstraintGraph()
{
// Sort the outgoing edges for each graph node so that the
// original order will be preserved as much as possible.
cmsys_stl::sort(i->begin(), i->end());
std::sort(i->begin(), i->end());
// Make the edge list unique.
EdgeList::iterator last = cmsys_stl::unique(i->begin(), i->end());
i->erase(last, i->end());
i->erase(std::unique(i->begin(), i->end()), i->end());
}
}

View File

@ -31,9 +31,6 @@ bool cmFLTKWrapUICommand
// get parameter for the command
this->Target = args[0]; // Target that will use the generated files
std::vector<std::string> newArgs;
this->Makefile->ExpandSourceListArguments(args,newArgs, 1);
// get the list of GUI files from which .cxx and .h will be generated
std::string outputDirectory = this->Makefile->GetCurrentOutputDirectory();
@ -45,8 +42,8 @@ bool cmFLTKWrapUICommand
this->Makefile->AddIncludeDirectories( outputDirectories );
}
for(std::vector<std::string>::iterator i = (newArgs.begin() + 1);
i != newArgs.end(); i++)
for(std::vector<std::string>::const_iterator i = (args.begin() + 1);
i != args.end(); i++)
{
cmSourceFile *curr = this->Makefile->GetSource(*i);
// if we should use the source GUI

View File

@ -71,7 +71,7 @@ static std::string fix_file_url_windows(const std::string& url)
std::string ret = url;
if(strncmp(url.c_str(), "file://", 7) == 0)
{
cmsys_stl::wstring wurl = cmsys::Encoding::ToWide(url);
std::wstring wurl = cmsys::Encoding::ToWide(url);
if(!wurl.empty())
{
int mblen = WideCharToMultiByte(CP_ACP, 0, wurl.c_str(), -1,
@ -1843,7 +1843,7 @@ bool cmFileCopier::InstallDirectory(const char* source,
if(!(strcmp(dir.GetFile(fileNum), ".") == 0 ||
strcmp(dir.GetFile(fileNum), "..") == 0))
{
cmsys_stl::string fromPath = source;
std::string fromPath = source;
fromPath += "/";
fromPath += dir.GetFile(fileNum);
std::string toPath = destination;

View File

@ -195,12 +195,12 @@ struct cmFindLibraryHelper
void RegexFromList(std::string& out, std::vector<std::string> const& in);
size_type GetPrefixIndex(std::string const& prefix)
{
return cmsys_stl::find(this->Prefixes.begin(), this->Prefixes.end(),
return std::find(this->Prefixes.begin(), this->Prefixes.end(),
prefix) - this->Prefixes.begin();
}
size_type GetSuffixIndex(std::string const& suffix)
{
return cmsys_stl::find(this->Suffixes.begin(), this->Suffixes.end(),
return std::find(this->Suffixes.begin(), this->Suffixes.end(),
suffix) - this->Suffixes.begin();
}
bool HasValidSuffix(std::string const& name);

View File

@ -15,9 +15,9 @@
// cmExecutableCommand
bool cmInstallFilesCommand
::InitialPass(std::vector<std::string> const& argsIn, cmExecutionStatus &)
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
{
if(argsIn.size() < 2)
if(args.size() < 2)
{
this->SetError("called with incorrect number of arguments");
return false;
@ -27,9 +27,6 @@ bool cmInstallFilesCommand
this->Makefile->GetLocalGenerator()
->GetGlobalGenerator()->EnableInstallTarget();
std::vector<std::string> args;
this->Makefile->ExpandSourceListArguments(argsIn, args, 2);
this->Destination = args[0];
if((args.size() > 1) && (args[1] == "FILES"))

View File

@ -3204,11 +3204,7 @@ cmLocalGenerator
std::string ssin = sin;
// Avoid full paths by removing leading slashes.
std::string::size_type pos = 0;
for(;pos < ssin.size() && ssin[pos] == '/'; ++pos)
{
}
ssin = ssin.substr(pos);
ssin.erase(0, ssin.find_first_not_of("/"));
// Avoid full paths by removing colons.
cmSystemTools::ReplaceString(ssin, ":", "_");
@ -3645,16 +3641,10 @@ bool cmLocalGenerator::NeedBackwardsCompatibility_2_4()
bool cmLocalGenerator::CheckDefinition(std::string const& define) const
{
// Many compilers do not support -DNAME(arg)=sdf so we disable it.
bool function_style = false;
for(const char* c = define.c_str(); *c && *c != '='; ++c)
std::string::size_type pos = define.find_first_of("(=");
if (pos != std::string::npos)
{
if(*c == '(')
{
function_style = true;
break;
}
}
if(function_style)
if (define[pos] == '(')
{
std::ostringstream e;
e << "WARNING: Function-style preprocessor definitions may not be "
@ -3665,6 +3655,7 @@ bool cmLocalGenerator::CheckDefinition(std::string const& define) const
cmSystemTools::Message(e.str().c_str());
return false;
}
}
// Many compilers do not support # in the value so we disable it.
if(define.find_first_of("#") != define.npos)

View File

@ -2400,14 +2400,10 @@ void cmLocalUnixMakefileGenerator3
// On UNIX we must construct a single shell command to change
// directory and build because make resets the directory between
// each command.
std::vector<std::string>::iterator i = commands.begin();
for (; i != commands.end(); ++i)
{
std::string cmd = cd_cmd;
cmd += this->ConvertToOutputForExisting(tgtDir, relRetDir);
cmd += " && ";
cmd += *i;
*i = cmd;
}
std::string outputForExisting =
this->ConvertToOutputForExisting(tgtDir, relRetDir);
std::string prefix = cd_cmd + outputForExisting + " && ";
std::transform(commands.begin(), commands.end(), commands.begin(),
std::bind1st(std::plus<std::string>(), prefix));
}
}

View File

@ -3576,19 +3576,6 @@ void cmMakefile::EnableLanguage(std::vector<std::string> const & lang,
optional);
}
void cmMakefile::ExpandSourceListArguments(
std::vector<std::string> const& arguments,
std::vector<std::string>& newargs, unsigned int /* start */) const
{
// now expand the args
unsigned int i;
for(i = 0; i < arguments.size(); ++i)
{
// List expansion will have been done already.
newargs.push_back(arguments[i]);
}
}
int cmMakefile::TryCompile(const std::string& srcdir,
const std::string& bindir,
const std::string& projectName,

View File

@ -599,17 +599,6 @@ public:
*/
void AddSystemIncludeDirectories(const std::set<std::string> &incs);
/** Expand out any arguements in the vector that have ; separated
* strings into multiple arguements. A new vector is created
* containing the expanded versions of all arguments in argsIn.
* This method differes from the one in cmSystemTools in that if
* the CmakeLists file is version 1.2 or earlier it will check for
* source lists being used without ${} around them
*/
void ExpandSourceListArguments(std::vector<std::string> const& argsIn,
std::vector<std::string>& argsOut,
unsigned int startArgumentIndex) const;
/** Get a cmSourceFile pointer for a given source name, if the name is
* not found, then a null pointer is returned.
*/

View File

@ -12,19 +12,15 @@
#include "cmQTWrapCPPCommand.h"
// cmQTWrapCPPCommand
bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& argsIn,
bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus &)
{
if(argsIn.size() < 3 )
if(args.size() < 3 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
// This command supports source list inputs for compatibility.
std::vector<std::string> args;
this->Makefile->ExpandSourceListArguments(argsIn, args, 2);
// Get the moc executable to run in the custom command.
const char* moc_exe =
this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE");
@ -35,7 +31,7 @@ bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& argsIn,
this->Makefile->GetSafeDefinition(sourceList);
// Create a rule for all sources listed.
for(std::vector<std::string>::iterator j = (args.begin() + 2);
for(std::vector<std::string>::const_iterator j = (args.begin() + 2);
j != args.end(); ++j)
{
cmSourceFile *curr = this->Makefile->GetSource(*j);

View File

@ -12,19 +12,15 @@
#include "cmQTWrapUICommand.h"
// cmQTWrapUICommand
bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& argsIn,
bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus &)
{
if(argsIn.size() < 4 )
if(args.size() < 4 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
// This command supports source list inputs for compatibility.
std::vector<std::string> args;
this->Makefile->ExpandSourceListArguments(argsIn, args, 3);
// Get the uic and moc executables to run in the custom commands.
const char* uic_exe =
this->Makefile->GetRequiredDefinition("QT_UIC_EXECUTABLE");
@ -40,7 +36,7 @@ bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& argsIn,
this->Makefile->GetSafeDefinition(sourceList);
// Create rules for all sources listed.
for(std::vector<std::string>::iterator j = (args.begin() + 3);
for(std::vector<std::string>::const_iterator j = (args.begin() + 3);
j != args.end(); ++j)
{
cmSourceFile *curr = this->Makefile->GetSource(*j);

View File

@ -35,19 +35,12 @@ bool cmSetTargetPropertiesCommand
doingFiles = false;
// now loop through the rest of the arguments, new style
++j;
while (j != args.end())
{
propertyPairs.push_back(*j);
++j;
if(j == args.end())
if (std::distance(j, args.end()) % 2 != 0)
{
this->SetError("called with incorrect number of arguments.");
return false;
}
propertyPairs.push_back(*j);
++j;
}
// break out of the loop because j is already == end
propertyPairs.insert(propertyPairs.end(), j, args.end());
break;
}
else if (doingFiles)

View File

@ -36,19 +36,12 @@ bool cmSetTestsPropertiesCommand
doingFiles = false;
// now loop through the rest of the arguments, new style
++j;
while (j != args.end())
{
propertyPairs.push_back(*j);
++j;
if(j == args.end())
if (std::distance(j, args.end()) % 2 != 0)
{
this->SetError("called with incorrect number of arguments.");
return false;
}
propertyPairs.push_back(*j);
++j;
}
// break out of the loop because j is already == end
propertyPairs.insert(propertyPairs.end(), j, args.end());
break;
}
else if (doingFiles)

View File

@ -367,13 +367,17 @@ bool cmSystemTools::IsInternallyOn(const char* val)
return false;
}
std::basic_string<char> v = val;
if (v.size() > 4)
{
return false;
}
for(std::basic_string<char>::iterator c = v.begin();
c != v.end(); c++)
{
*c = static_cast<char>(toupper(*c));
}
return (v == "I_ON" || v == "i_on");
return v == "I_ON";
}
bool cmSystemTools::IsOn(const char* val)
@ -2702,7 +2706,7 @@ bool cmSystemTools::RemoveRPath(std::string const& file, std::string* emsg,
}
if(se_count == 2 && se[1]->IndexInSection < se[0]->IndexInSection)
{
cmsys_stl::swap(se[0], se[1]);
std::swap(se[0], se[1]);
}
// Get the size of the dynamic section header.

View File

@ -1153,15 +1153,11 @@ cmTarget::LinkLibraryType cmTarget::ComputeLinkType(
// Check if any entry in the list matches this configuration.
std::string configUpper = cmSystemTools::UpperCase(config);
for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
i != debugConfigs.end(); ++i)
{
if(*i == configUpper)
if (std::find(debugConfigs.begin(), debugConfigs.end(), configUpper) !=
debugConfigs.end())
{
return cmTarget::DEBUG;
}
}
// The current configuration is not a debug configuration.
return cmTarget::OPTIMIZED;
}
@ -5919,8 +5915,7 @@ cmTarget::GetCompatibleInterfaces(std::string const& config) const
{ \
std::vector<std::string> props; \
cmSystemTools::ExpandListArgument(prop, props); \
std::copy(props.begin(), props.end(), \
std::inserter(compat.Props##x, compat.Props##x.begin())); \
compat.Props##x.insert(props.begin(), props.end()); \
}
CM_READ_COMPATIBLE_INTERFACE(BOOL, Bool)
CM_READ_COMPATIBLE_INTERFACE(STRING, String)

View File

@ -28,7 +28,7 @@ cmXMLSafe::cmXMLSafe(const char* s):
}
//----------------------------------------------------------------------------
cmXMLSafe::cmXMLSafe(cmsys_stl::string const& s):
cmXMLSafe::cmXMLSafe(std::string const& s):
Data(s.c_str()),
Size(static_cast<unsigned long>(s.length())),
DoQuotes(true)
@ -43,7 +43,7 @@ cmXMLSafe& cmXMLSafe::Quotes(bool b)
}
//----------------------------------------------------------------------------
cmsys_stl::string cmXMLSafe::str()
std::string cmXMLSafe::str()
{
cmsys_ios::ostringstream ss;
ss << *this;

View File

@ -24,7 +24,7 @@ public:
/** Construct with the data to be written. This assumes the data
will exist for the duration of this object's life. */
cmXMLSafe(const char* s);
cmXMLSafe(cmsys_stl::string const& s);
cmXMLSafe(std::string const& s);
/** Specify whether to escape quotes too. This is needed when
writing the content of an attribute value. By default quotes
@ -32,7 +32,7 @@ public:
cmXMLSafe& Quotes(bool b = true);
/** Get the escaped data as a string. */
cmsys_stl::string str();
std::string str();
private:
char const* Data;
unsigned long Size;

View File

@ -2731,11 +2731,10 @@ std::vector<std::string> const& cmake::GetDebugConfigs()
{
// Expand the specified list and convert to upper-case.
cmSystemTools::ExpandListArgument(config_list, this->DebugConfigs);
for(std::vector<std::string>::iterator i = this->DebugConfigs.begin();
i != this->DebugConfigs.end(); ++i)
{
*i = cmSystemTools::UpperCase(*i);
}
std::transform(this->DebugConfigs.begin(),
this->DebugConfigs.end(),
this->DebugConfigs.begin(),
cmSystemTools::UpperCase);
}
// If no configurations were specified, use a default list.
if(this->DebugConfigs.empty())