From ac26d4b343aece40b6b9a931ab619fc88d4b9492 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 10 Feb 2015 21:50:16 +0100 Subject: Split cmAlgorithms into a separate header file. --- Source/CPack/cmCPackGeneratorFactory.cxx | 1 + Source/CTest/cmCTestGIT.cxx | 1 + Source/cmAlgorithms.h | 151 +++++++++++++++++++++++++++++++ Source/cmExportSet.cxx | 1 + Source/cmExportSetMap.cxx | 1 + Source/cmFileLockPool.cxx | 1 + Source/cmInstalledFile.h | 1 + Source/cmRST.cxx | 1 + Source/cmStandardIncludes.h | 134 --------------------------- Source/cmSystemTools.cxx | 1 + Source/cmVariableWatch.cxx | 2 + 11 files changed, 161 insertions(+), 134 deletions(-) create mode 100644 Source/cmAlgorithms.h diff --git a/Source/CPack/cmCPackGeneratorFactory.cxx b/Source/CPack/cmCPackGeneratorFactory.cxx index a07c29a..4626142 100644 --- a/Source/CPack/cmCPackGeneratorFactory.cxx +++ b/Source/CPack/cmCPackGeneratorFactory.cxx @@ -46,6 +46,7 @@ #endif #include "cmCPackLog.h" +#include "cmAlgorithms.h" //---------------------------------------------------------------------- diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx index 98bc9d7..6b84bab 100644 --- a/Source/CTest/cmCTestGIT.cxx +++ b/Source/CTest/cmCTestGIT.cxx @@ -13,6 +13,7 @@ #include "cmCTest.h" #include "cmSystemTools.h" +#include "cmAlgorithms.h" #include "cmXMLSafe.h" #include diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h new file mode 100644 index 0000000..4938140 --- /dev/null +++ b/Source/cmAlgorithms.h @@ -0,0 +1,151 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2015 Stephen Kelly + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#ifndef cmAlgorithms_h +#define cmAlgorithms_h + +#include "cmStandardIncludes.h" + +inline bool cmHasLiteralPrefixImpl(const std::string &str1, + const char *str2, + size_t N) +{ + return strncmp(str1.c_str(), str2, N) == 0; +} + +inline bool cmHasLiteralPrefixImpl(const char* str1, + const char *str2, + size_t N) +{ + return strncmp(str1, str2, N) == 0; +} + +inline bool cmHasLiteralSuffixImpl(const std::string &str1, + const char *str2, + size_t N) +{ + size_t len = str1.size(); + return len >= N && strcmp(str1.c_str() + len - N, str2) == 0; +} + +inline bool cmHasLiteralSuffixImpl(const char* str1, + const char* str2, + size_t N) +{ + size_t len = strlen(str1); + return len >= N && strcmp(str1 + len - N, str2) == 0; +} + +template +const T* cmArrayBegin(const T (&a)[N]) { return a; } +template +const T* cmArrayEnd(const T (&a)[N]) { return a + N; } +template +size_t cmArraySize(const T (&)[N]) { return N; } + +template +bool cmHasLiteralPrefix(T str1, const char (&str2)[N]) +{ + return cmHasLiteralPrefixImpl(str1, str2, N - 1); +} + +template +bool cmHasLiteralSuffix(T str1, const char (&str2)[N]) +{ + return cmHasLiteralSuffixImpl(str1, str2, N - 1); +} + +struct cmStrCmp { + cmStrCmp(const char *test) : m_test(test) {} + cmStrCmp(const std::string &test) : m_test(test) {} + + bool operator()(const std::string& input) const + { + return m_test == input; + } + + bool operator()(const char * input) const + { + return strcmp(input, m_test.c_str()) == 0; + } + +private: + const std::string m_test; +}; + +namespace ContainerAlgorithms { + +template +struct cmIsPair +{ + enum { value = false }; +}; + +template +struct cmIsPair > +{ + enum { value = true }; +}; + +template::value> +struct DefaultDeleter +{ + void operator()(typename Container::value_type value) { + delete value; + } +}; + +template +struct DefaultDeleter +{ + void operator()(typename Container::value_type value) { + delete value.second; + } +}; + +} + +template +void cmDeleteAll(Container const& c) +{ + std::for_each(c.begin(), c.end(), + ContainerAlgorithms::DefaultDeleter()); +} + +template +std::string cmJoin(Range const& r, const char* delimiter) +{ + if (r.empty()) + { + return std::string(); + } + std::ostringstream os; + typedef typename Range::value_type ValueType; + typedef typename Range::const_iterator InputIt; + InputIt first = r.begin(); + InputIt last = r.end(); + --last; + std::copy(first, last, + std::ostream_iterator(os, delimiter)); + + os << *last; + + return os.str(); +} + +template +std::string cmJoin(Range const& r, std::string delimiter) +{ + return cmJoin(r, delimiter.c_str()); +}; + +#endif diff --git a/Source/cmExportSet.cxx b/Source/cmExportSet.cxx index 14812e4..4148fb5 100644 --- a/Source/cmExportSet.cxx +++ b/Source/cmExportSet.cxx @@ -12,6 +12,7 @@ #include "cmExportSet.h" #include "cmTargetExport.h" +#include "cmAlgorithms.h" cmExportSet::~cmExportSet() { diff --git a/Source/cmExportSetMap.cxx b/Source/cmExportSetMap.cxx index 14c4458..cf431c6 100644 --- a/Source/cmExportSetMap.cxx +++ b/Source/cmExportSetMap.cxx @@ -12,6 +12,7 @@ #include "cmExportSetMap.h" #include "cmExportSet.h" +#include "cmAlgorithms.h" cmExportSet* cmExportSetMap::operator[](const std::string &name) { diff --git a/Source/cmFileLockPool.cxx b/Source/cmFileLockPool.cxx index cf8e9a9..3710eb0 100644 --- a/Source/cmFileLockPool.cxx +++ b/Source/cmFileLockPool.cxx @@ -16,6 +16,7 @@ #include "cmFileLock.h" #include "cmFileLockResult.h" +#include "cmAlgorithms.h" cmFileLockPool::cmFileLockPool() { diff --git a/Source/cmInstalledFile.h b/Source/cmInstalledFile.h index 503f92c..cdb0866 100644 --- a/Source/cmInstalledFile.h +++ b/Source/cmInstalledFile.h @@ -13,6 +13,7 @@ #define cmInstalledFile_h #include "cmGeneratorExpression.h" +#include "cmAlgorithms.h" /** \class cmInstalledFile * \brief Represents a file intended for installation. diff --git a/Source/cmRST.cxx b/Source/cmRST.cxx index f4607c6..d20d999 100644 --- a/Source/cmRST.cxx +++ b/Source/cmRST.cxx @@ -12,6 +12,7 @@ #include "cmRST.h" #include "cmSystemTools.h" +#include "cmAlgorithms.h" #include "cmVersion.h" #include #include diff --git a/Source/cmStandardIncludes.h b/Source/cmStandardIncludes.h index 77b4f62..a9796b9 100644 --- a/Source/cmStandardIncludes.h +++ b/Source/cmStandardIncludes.h @@ -131,138 +131,4 @@ static thisClass* SafeDownCast(cmObject *c) \ } \ class cmTypeMacro_UseTrailingSemicolon -template -std::string cmJoin(Range const& r, const char* delimiter) -{ - if (r.empty()) - { - return std::string(); - } - std::ostringstream os; - typedef typename Range::value_type ValueType; - typedef typename Range::const_iterator InputIt; - InputIt first = r.begin(); - InputIt last = r.end(); - --last; - std::copy(first, last, - std::ostream_iterator(os, delimiter)); - - os << *last; - - return os.str(); -} - -template -std::string cmJoin(Range const& r, std::string delimiter) -{ - return cmJoin(r, delimiter.c_str()); -}; - -inline bool cmHasLiteralPrefixImpl(const std::string &str1, - const char *str2, - size_t N) -{ - return strncmp(str1.c_str(), str2, N) == 0; -} - -inline bool cmHasLiteralPrefixImpl(const char* str1, - const char *str2, - size_t N) -{ - return strncmp(str1, str2, N) == 0; -} - -inline bool cmHasLiteralSuffixImpl(const std::string &str1, - const char *str2, - size_t N) -{ - size_t len = str1.size(); - return len >= N && strcmp(str1.c_str() + len - N, str2) == 0; -} - -inline bool cmHasLiteralSuffixImpl(const char* str1, - const char* str2, - size_t N) -{ - size_t len = strlen(str1); - return len >= N && strcmp(str1 + len - N, str2) == 0; -} - -template -const T* cmArrayBegin(const T (&a)[N]) { return a; } -template -const T* cmArrayEnd(const T (&a)[N]) { return a + N; } -template -size_t cmArraySize(const T (&)[N]) { return N; } - -template -bool cmHasLiteralPrefix(T str1, const char (&str2)[N]) -{ - return cmHasLiteralPrefixImpl(str1, str2, N - 1); -} - -template -bool cmHasLiteralSuffix(T str1, const char (&str2)[N]) -{ - return cmHasLiteralSuffixImpl(str1, str2, N - 1); -} - -struct cmStrCmp { - cmStrCmp(const char *test) : m_test(test) {} - cmStrCmp(const std::string &test) : m_test(test) {} - - bool operator()(const std::string& input) const - { - return m_test == input; - } - - bool operator()(const char * input) const - { - return strcmp(input, m_test.c_str()) == 0; - } - -private: - const std::string m_test; -}; - -namespace ContainerAlgorithms { - -template -struct cmIsPair -{ - enum { value = false }; -}; - -template -struct cmIsPair > -{ - enum { value = true }; -}; - -template::value> -struct DefaultDeleter -{ - void operator()(typename Container::value_type value) { - delete value; - } -}; - -template -struct DefaultDeleter -{ - void operator()(typename Container::value_type value) { - delete value.second; - } -}; - -} - -template -void cmDeleteAll(Container const& c) -{ - std::for_each(c.begin(), c.end(), - ContainerAlgorithms::DefaultDeleter()); -} - #endif diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 7dd6121..bf496e9 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -11,6 +11,7 @@ ============================================================================*/ #include "cmSystemTools.h" +#include "cmAlgorithms.h" #include #include #include diff --git a/Source/cmVariableWatch.cxx b/Source/cmVariableWatch.cxx index b8a6df2..57dde31 100644 --- a/Source/cmVariableWatch.cxx +++ b/Source/cmVariableWatch.cxx @@ -11,6 +11,8 @@ ============================================================================*/ #include "cmVariableWatch.h" +#include "cmAlgorithms.h" + static const char* const cmVariableWatchAccessStrings[] = { "READ_ACCESS", -- cgit v0.12 From 9fe8f49353f927882af256c7870eb24e4be0c9be Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 11 Feb 2015 00:29:20 +0100 Subject: cmMacroCommand: Replace a loop with cmJoin. --- Source/cmMacroCommand.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index 69fcca7..e7c6a29 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -262,11 +262,11 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf, if (!this->Depth) { std::string name = this->Args[0]; - std::vector::size_type cc; name += "("; - for ( cc = 0; cc < this->Args.size(); cc ++ ) + if (!this->Args.empty()) { - name += " " + this->Args[cc]; + name += " "; + name += cmJoin(this->Args, " "); } name += " )"; mf.AddMacro(this->Args[0].c_str(), name.c_str()); -- cgit v0.12 From f95543f8a6b38bf6d5350169bdb53d5066839b76 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 25 Jan 2015 15:42:12 +0100 Subject: cmMacroCommand: Extract iteration starting point. --- Source/cmMacroCommand.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index e7c6a29..c1eb35e 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -164,9 +164,10 @@ bool cmMacroHelperCommand::InvokeInitialPass { if (!argnDefInitialized) { - std::vector::const_iterator eit; + std::vector::const_iterator eit + = expandedArgs.begin(); std::vector::size_type cnt = 0; - for(eit = expandedArgs.begin(); eit != expandedArgs.end(); ++eit) + for( ; eit != expandedArgs.end(); ++eit) { if ( cnt >= this->Args.size()-1 ) { -- cgit v0.12 From 11ecc31d0a2da0090195a682364fb4628f55673a Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 25 Jan 2015 15:44:49 +0100 Subject: cmMacroCommand: Execute loop only if it has an effect. --- Source/cmMacroCommand.cxx | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index c1eb35e..c1e7cbb 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -164,20 +164,23 @@ bool cmMacroHelperCommand::InvokeInitialPass { if (!argnDefInitialized) { - std::vector::const_iterator eit - = expandedArgs.begin(); - std::vector::size_type cnt = 0; - for( ; eit != expandedArgs.end(); ++eit) + if (expandedArgs.size() > this->Args.size() - 1) { - if ( cnt >= this->Args.size()-1 ) + std::vector::const_iterator eit + = expandedArgs.begin(); + std::vector::size_type cnt = 0; + for( ; eit != expandedArgs.end(); ++eit) { - if (!argnDef.empty()) + if ( cnt >= this->Args.size()-1 ) { - argnDef += ";"; + if (!argnDef.empty()) + { + argnDef += ";"; + } + argnDef += *eit; } - argnDef += *eit; + cnt ++; } - cnt ++; } argnDefInitialized = true; } -- cgit v0.12 From 0a4e5674eccb0126733086d4632c7239217db6f1 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 25 Jan 2015 15:47:21 +0100 Subject: cmMacroCommand: Remove counting variable. Start iteration at correct starting point directly. --- Source/cmMacroCommand.cxx | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index c1e7cbb..657e750 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -167,19 +167,14 @@ bool cmMacroHelperCommand::InvokeInitialPass if (expandedArgs.size() > this->Args.size() - 1) { std::vector::const_iterator eit - = expandedArgs.begin(); - std::vector::size_type cnt = 0; + = expandedArgs.begin() + (this->Args.size() - 1); for( ; eit != expandedArgs.end(); ++eit) { - if ( cnt >= this->Args.size()-1 ) + if (!argnDef.empty()) { - if (!argnDef.empty()) - { - argnDef += ";"; - } - argnDef += *eit; + argnDef += ";"; } - cnt ++; + argnDef += *eit; } } argnDefInitialized = true; -- cgit v0.12 From 7ee56f03999e8605cc2cbe85a3a7b7159e639e5d Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 17 Jan 2015 17:47:10 +0100 Subject: Convert loops into the commonly used pattern. --- Source/cmGetCMakePropertyCommand.cxx | 23 ++++++++++++----------- Source/cmMakefile.cxx | 34 +++++++++++++--------------------- 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/Source/cmGetCMakePropertyCommand.cxx b/Source/cmGetCMakePropertyCommand.cxx index e193cf5..c0e4683 100644 --- a/Source/cmGetCMakePropertyCommand.cxx +++ b/Source/cmGetCMakePropertyCommand.cxx @@ -25,7 +25,6 @@ bool cmGetCMakePropertyCommand return false; } - std::vector::size_type cc; std::string variable = args[0]; std::string output = "NOTFOUND"; @@ -35,12 +34,15 @@ bool cmGetCMakePropertyCommand std::vector vars = this->Makefile->GetDefinitions(cacheonly); if (!vars.empty()) { - output = vars[0]; - } - for ( cc = 1; cc < vars.size(); ++cc ) - { - output += ";"; - output += vars[cc]; + output = ""; + const char* sep = ""; + std::vector::size_type cc; + for ( cc = 0; cc < vars.size(); ++cc ) + { + output += sep; + output += vars[cc]; + sep = ";"; + } } } else if ( args[1] == "MACROS" ) @@ -54,13 +56,12 @@ bool cmGetCMakePropertyCommand ->GetInstallComponents(); std::set::const_iterator compIt; output = ""; + const char* sep = ""; for (compIt = components->begin(); compIt != components->end(); ++compIt) { - if (compIt != components->begin()) - { - output += ";"; - } + output += sep; output += *compIt; + sep = ";"; } } else diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index eb68e49..aca4413 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -3752,15 +3752,12 @@ void cmMakefile::GetListOfMacros(std::string& macros) const { StringStringMap::const_iterator it; macros = ""; - int cc = 0; + const char* sep = ""; for ( it = this->MacrosMap.begin(); it != this->MacrosMap.end(); ++it ) { - if ( cc > 0 ) - { - macros += ";"; - } + macros += sep; macros += it->first; - cc ++; + sep = ""; } } @@ -4205,15 +4202,14 @@ const char *cmMakefile::GetProperty(const std::string& prop, } else if (prop == "LISTFILE_STACK") { + const char* sep = ""; for (std::deque::const_iterator i = this->ListFileStack.begin(); i != this->ListFileStack.end(); ++i) { - if (i != this->ListFileStack.begin()) - { - output += ";"; - } + output += sep; output += *i; + sep = ";"; } return output.c_str(); } @@ -4225,13 +4221,12 @@ const char *cmMakefile::GetProperty(const std::string& prop, cacheonly = 1; } std::vector vars = this->GetDefinitions(cacheonly); + const char* sep = ""; for (unsigned int cc = 0; cc < vars.size(); cc ++ ) { - if ( cc > 0 ) - { - output += ";"; - } + output += sep; output += vars[cc]; + sep = ";"; } return output.c_str(); } @@ -4247,19 +4242,16 @@ const char *cmMakefile::GetProperty(const std::string& prop, } else if (prop == "LINK_DIRECTORIES") { - std::ostringstream str; + const char* sep = ""; for (std::vector::const_iterator it = this->GetLinkDirectories().begin(); it != this->GetLinkDirectories().end(); ++ it ) { - if ( it != this->GetLinkDirectories().begin()) - { - str << ";"; - } - str << it->c_str(); + output += sep; + output += *it; + sep = ";"; } - output = str.str(); return output.c_str(); } else if (prop == "INCLUDE_DIRECTORIES") -- cgit v0.12 From 7b8725bf8472ebf4781ddd60ef8fcca9c3ad98dd Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 17 Jan 2015 17:36:19 +0100 Subject: Convert loops populating maybe-empty content into the common pattern. --- Source/cmListCommand.cxx | 12 ++++++++---- Source/cmLocalGenerator.cxx | 12 ++++++++---- Source/cmMacroCommand.cxx | 23 ++++++++++++++--------- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index 107dca9..8d1657d 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -254,14 +254,18 @@ bool cmListCommand::HandleAppendCommand(std::vector const& args) // expand the variable std::string listString; this->GetListString(listString, listName); + + if(!listString.empty() && !args.empty()) + { + listString += ";"; + } + const char* sep = ""; size_t cc; for ( cc = 2; cc < args.size(); ++ cc ) { - if(!listString.empty()) - { - listString += ";"; - } + listString += sep; listString += args[cc]; + sep = ";"; } this->Makefile->AddDefinition(listName, listString.c_str()); diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 7afe05f..05d8ab5 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -3011,13 +3011,17 @@ cmLocalGenerator::ConvertToRelativePath(const std::vector& local, // trailing slash in the input then the last iteration of the loop // will add a slash followed by an empty string which will preserve // the trailing slash in the output. + + if(!relative.empty() && !remote.empty()) + { + relative += "/"; + } + const char* sep = ""; for(unsigned int i=common; i < remote.size(); ++i) { - if(!relative.empty()) - { - relative += "/"; - } + relative += sep; relative += remote[i]; + sep = "/"; } // Finally return the path. diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index 657e750..81aaf3e 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -166,15 +166,17 @@ bool cmMacroHelperCommand::InvokeInitialPass { if (expandedArgs.size() > this->Args.size() - 1) { + if (!argnDef.empty() && !expandedArgs.empty()) + { + argnDef += ";"; + } std::vector::const_iterator eit = expandedArgs.begin() + (this->Args.size() - 1); + const char* sep = ""; for( ; eit != expandedArgs.end(); ++eit) { - if (!argnDef.empty()) - { - argnDef += ";"; - } - argnDef += *eit; + argnDef += sep + *eit; + sep = ";"; } } argnDefInitialized = true; @@ -191,14 +193,17 @@ bool cmMacroHelperCommand::InvokeInitialPass // repleace ARGV, compute it only once if (!argvDefInitialized) { + if (!argvDef.empty() && !expandedArgs.empty()) + { + argvDef += ";"; + } + const char* sep = ""; std::vector::const_iterator eit; for(eit = expandedArgs.begin(); eit != expandedArgs.end(); ++eit) { - if (!argvDef.empty()) - { - argvDef += ";"; - } + argvDef += sep; argvDef += *eit; + sep = ";"; } argvDefInitialized = true; } -- cgit v0.12 From 8910224950a2b723e0d4fd7c21a326af7fb2e050 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 14 Jan 2015 21:31:46 +0100 Subject: Replace common loop pattern with cmJoin --- Source/cmFindPackageCommand.cxx | 19 ++----------------- Source/cmFunctionCommand.cxx | 8 ++------ Source/cmGetCMakePropertyCommand.cxx | 20 ++------------------ Source/cmMacroCommand.cxx | 9 +-------- Source/cmMakefile.cxx | 30 +++--------------------------- Source/cmOptionCommand.cxx | 6 +----- 6 files changed, 11 insertions(+), 81 deletions(-) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 7746980..fd9b236 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -1064,26 +1064,11 @@ void cmFindPackageCommand::AppendToFoundProperty(bool found) } - std::string tmp; - const char* sep =""; - for(size_t i=0; iMakefile->GetCMakeInstance()->SetProperty("PACKAGES_FOUND", tmp.c_str()); - tmp = ""; - sep = ""; - for(size_t i=0; iMakefile->GetCMakeInstance()->SetProperty("PACKAGES_NOT_FOUND", tmp.c_str()); } diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx index c33048c..b44e228 100644 --- a/Source/cmFunctionCommand.cxx +++ b/Source/cmFunctionCommand.cxx @@ -193,12 +193,8 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf, if (!this->Depth) { std::string name = this->Args[0]; - std::vector::size_type cc; - name += "("; - for ( cc = 0; cc < this->Args.size(); cc ++ ) - { - name += " " + this->Args[cc]; - } + name += "( "; + name += cmJoin(this->Args, " "); name += " )"; // create a new command and add it to cmake diff --git a/Source/cmGetCMakePropertyCommand.cxx b/Source/cmGetCMakePropertyCommand.cxx index c0e4683..84c00ba 100644 --- a/Source/cmGetCMakePropertyCommand.cxx +++ b/Source/cmGetCMakePropertyCommand.cxx @@ -34,15 +34,7 @@ bool cmGetCMakePropertyCommand std::vector vars = this->Makefile->GetDefinitions(cacheonly); if (!vars.empty()) { - output = ""; - const char* sep = ""; - std::vector::size_type cc; - for ( cc = 0; cc < vars.size(); ++cc ) - { - output += sep; - output += vars[cc]; - sep = ";"; - } + output = cmJoin(vars, ";"); } } else if ( args[1] == "MACROS" ) @@ -54,15 +46,7 @@ bool cmGetCMakePropertyCommand const std::set* components = this->Makefile->GetLocalGenerator()->GetGlobalGenerator() ->GetInstallComponents(); - std::set::const_iterator compIt; - output = ""; - const char* sep = ""; - for (compIt = components->begin(); compIt != components->end(); ++compIt) - { - output += sep; - output += *compIt; - sep = ";"; - } + output = cmJoin(*components, ";"); } else { diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index 81aaf3e..676e082 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -197,14 +197,7 @@ bool cmMacroHelperCommand::InvokeInitialPass { argvDef += ";"; } - const char* sep = ""; - std::vector::const_iterator eit; - for(eit = expandedArgs.begin(); eit != expandedArgs.end(); ++eit) - { - argvDef += sep; - argvDef += *eit; - sep = ";"; - } + argvDef += cmJoin(expandedArgs, ";"); argvDefInitialized = true; } cmSystemTools::ReplaceString(tmps, "${ARGV}", argvDef.c_str()); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index aca4413..ac5fec9 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4202,15 +4202,7 @@ const char *cmMakefile::GetProperty(const std::string& prop, } else if (prop == "LISTFILE_STACK") { - const char* sep = ""; - for (std::deque::const_iterator - i = this->ListFileStack.begin(); - i != this->ListFileStack.end(); ++i) - { - output += sep; - output += *i; - sep = ";"; - } + output = cmJoin(this->ListFileStack, ";"); return output.c_str(); } else if (prop == "VARIABLES" || prop == "CACHE_VARIABLES") @@ -4220,14 +4212,7 @@ const char *cmMakefile::GetProperty(const std::string& prop, { cacheonly = 1; } - std::vector vars = this->GetDefinitions(cacheonly); - const char* sep = ""; - for (unsigned int cc = 0; cc < vars.size(); cc ++ ) - { - output += sep; - output += vars[cc]; - sep = ";"; - } + output = cmJoin(this->GetDefinitions(cacheonly), ";"); return output.c_str(); } else if (prop == "MACROS") @@ -4242,16 +4227,7 @@ const char *cmMakefile::GetProperty(const std::string& prop, } else if (prop == "LINK_DIRECTORIES") { - const char* sep = ""; - for (std::vector::const_iterator - it = this->GetLinkDirectories().begin(); - it != this->GetLinkDirectories().end(); - ++ it ) - { - output += sep; - output += *it; - sep = ";"; - } + output = cmJoin(this->GetLinkDirectories(), ";"); return output.c_str(); } else if (prop == "INCLUDE_DIRECTORIES") diff --git a/Source/cmOptionCommand.cxx b/Source/cmOptionCommand.cxx index e505440..60728ea 100644 --- a/Source/cmOptionCommand.cxx +++ b/Source/cmOptionCommand.cxx @@ -34,11 +34,7 @@ bool cmOptionCommand if(argError) { std::string m = "called with incorrect number of arguments: "; - for(size_t i =0; i < args.size(); ++i) - { - m += args[i]; - m += " "; - } + m += cmJoin(args, " "); this->SetError(m); return false; } -- cgit v0.12 From 4e78ebbdf94b99f7b7d5b9b31d05dd9479b1d6ab Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 10 Feb 2015 22:19:21 +0100 Subject: cmAlgorithms: Add a Range container and adaptor method. This can make a pair of iterators API compatible with the cmJoin algorithm and other range-based algorithms. Accept different iterator types in the cmRange adaptor so that a const and non-const iterator are accepted. --- Source/cmAlgorithms.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index 4938140..6c03f51 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -112,6 +112,27 @@ struct DefaultDeleter } }; +template +struct Range +{ + typedef const_iterator_ const_iterator; + typedef typename std::iterator_traits::value_type value_type; + Range(const_iterator begin_, const_iterator end_) + : Begin(begin_), End(end_) {} + const_iterator begin() const { return Begin; } + const_iterator end() const { return End; } + bool empty() const { return std::distance(Begin, End) == 0; } +private: + const_iterator Begin; + const_iterator End; +}; + +} + +template +ContainerAlgorithms::Range cmRange(Iter1 begin, Iter2 end) +{ + return ContainerAlgorithms::Range(begin, end); } template -- cgit v0.12 From 27c6f017a1ef7c62f7f0332d624add7e8189f81c Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 14 Jan 2015 21:27:25 +0100 Subject: Use cmJoin to accumulate string ranges. Avoid using the std::accumulate algorithm which is designed for numeric types, not complex types. It introduces unneccessary copies. Initialize variables where they are populated. --- Source/cmFileCommand.cxx | 6 +----- Source/cmMessageCommand.cxx | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 8b893bc..212603c 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -217,7 +217,6 @@ bool cmFileCommand bool cmFileCommand::HandleWriteCommand(std::vector const& args, bool append) { - std::string message; std::vector::const_iterator i = args.begin(); i++; // Get rid of subcommand @@ -231,10 +230,6 @@ bool cmFileCommand::HandleWriteCommand(std::vector const& args, i++; - for(;i != args.end(); ++i) - { - message += *i; - } if ( !this->Makefile->CanIWriteThisFile(fileName.c_str()) ) { std::string e @@ -272,6 +267,7 @@ bool cmFileCommand::HandleWriteCommand(std::vector const& args, this->SetError(error); return false; } + std::string message = cmJoin(cmRange(i, args.end()), std::string()); file << message; file.close(); if(mode) diff --git a/Source/cmMessageCommand.cxx b/Source/cmMessageCommand.cxx index 88d6a77..0449c50 100644 --- a/Source/cmMessageCommand.cxx +++ b/Source/cmMessageCommand.cxx @@ -20,7 +20,6 @@ bool cmMessageCommand this->SetError("called with incorrect number of arguments"); return false; } - std::string message; std::vector::const_iterator i = args.begin(); cmake::MessageType type = cmake::MESSAGE; @@ -70,10 +69,7 @@ bool cmMessageCommand ++i; } - for(;i != args.end(); ++i) - { - message += *i; - } + std::string message = cmJoin(cmRange(i, args.end()), std::string()); if (type != cmake::MESSAGE) { -- cgit v0.12 From 0c12f1ea0da0a5822a7a69b4ff77b45732c72466 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 10 Feb 2015 22:14:54 +0100 Subject: cmAlgorithms: Add a range adaptor and API for adjusting a range. --- Source/cmAlgorithms.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index 6c03f51..ad2b9c1 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -122,6 +122,17 @@ struct Range const_iterator begin() const { return Begin; } const_iterator end() const { return End; } bool empty() const { return std::distance(Begin, End) == 0; } + Range& advance(cmIML_INT_intptr_t amount) + { + std::advance(Begin, amount); + return *this; + } + + Range& retreat(cmIML_INT_intptr_t amount) + { + std::advance(End, -amount); + return *this; + } private: const_iterator Begin; const_iterator End; @@ -135,6 +146,14 @@ ContainerAlgorithms::Range cmRange(Iter1 begin, Iter2 end) return ContainerAlgorithms::Range(begin, end); } +template +ContainerAlgorithms::Range +cmRange(Range const& range) +{ + return ContainerAlgorithms::Range( + range.begin(), range.end()); +} + template void cmDeleteAll(Container const& c) { -- cgit v0.12 From bb10012fea677fd8aa1bbefd06061efcb7ec1955 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 10 Feb 2015 22:23:41 +0100 Subject: cmStringCommand: Accumulate with cmJoin and range adaptors. --- Source/cmStringCommand.cxx | 42 +++++++++++------------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index 3e606d7..edc6afc 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -303,13 +303,6 @@ bool cmStringCommand::RegexMatch(std::vector const& args) std::string regex = args[2]; std::string outvar = args[3]; - // Concatenate all the last arguments together. - std::string input = args[4]; - for(unsigned int i=5; i < args.size(); ++i) - { - input += args[i]; - } - this->Makefile->ClearMatches(); // Compile the regular expression. cmsys::RegularExpression re; @@ -321,6 +314,9 @@ bool cmStringCommand::RegexMatch(std::vector const& args) return false; } + // Concatenate all the last arguments together. + std::string input = cmJoin(cmRange(args).advance(4), std::string()); + // Scan through the input for all matches. std::string output; if(re.find(input.c_str())) @@ -352,13 +348,6 @@ bool cmStringCommand::RegexMatchAll(std::vector const& args) std::string regex = args[2]; std::string outvar = args[3]; - // Concatenate all the last arguments together. - std::string input = args[4]; - for(unsigned int i=5; i < args.size(); ++i) - { - input += args[i]; - } - this->Makefile->ClearMatches(); // Compile the regular expression. cmsys::RegularExpression re; @@ -371,6 +360,9 @@ bool cmStringCommand::RegexMatchAll(std::vector const& args) return false; } + // Concatenate all the last arguments together. + std::string input = cmJoin(cmRange(args).advance(4), std::string()); + // Scan through the input for all matches. std::string output; const char* p = input.c_str(); @@ -456,13 +448,6 @@ bool cmStringCommand::RegexReplace(std::vector const& args) l = r; } - // Concatenate all the last arguments together. - std::string input = args[5]; - for(unsigned int i=6; i < args.size(); ++i) - { - input += args[i]; - } - this->Makefile->ClearMatches(); // Compile the regular expression. cmsys::RegularExpression re; @@ -475,6 +460,9 @@ bool cmStringCommand::RegexReplace(std::vector const& args) return false; } + // Concatenate all the last arguments together. + std::string input = cmJoin(cmRange(args).advance(5), std::string()); + // Scan through the input for all matches. std::string output; std::string::size_type base = 0; @@ -673,11 +661,7 @@ bool cmStringCommand::HandleReplaceCommand(std::vector const& const std::string& replaceExpression = args[2]; const std::string& variableName = args[3]; - std::string input = args[4]; - for(unsigned int i=5; i < args.size(); ++i) - { - input += args[i]; - } + std::string input = cmJoin(cmRange(args).advance(4), std::string()); cmsys::SystemTools::ReplaceString(input, matchExpression.c_str(), replaceExpression.c_str()); @@ -756,11 +740,7 @@ bool cmStringCommand } std::string const& variableName = args[1]; - std::string value; - for(unsigned int i = 2; i < args.size(); ++i) - { - value += args[i]; - } + std::string value = cmJoin(cmRange(args).advance(2), std::string()); this->Makefile->AddDefinition(variableName, value.c_str()); return true; -- cgit v0.12 From 9380e85f865e29cd5968e91408a31d5160f4a4cb Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 25 Jan 2015 15:53:20 +0100 Subject: Convert loops to cmJoin algorithm with cmRange. --- Source/cmListCommand.cxx | 9 +-------- Source/cmLocalGenerator.cxx | 8 +------- Source/cmMacroCommand.cxx | 7 +------ Source/cmcmd.cxx | 15 ++------------- 4 files changed, 5 insertions(+), 34 deletions(-) diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index 8d1657d..dd0cfa9 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -259,14 +259,7 @@ bool cmListCommand::HandleAppendCommand(std::vector const& args) { listString += ";"; } - const char* sep = ""; - size_t cc; - for ( cc = 2; cc < args.size(); ++ cc ) - { - listString += sep; - listString += args[cc]; - sep = ";"; - } + listString += cmJoin(cmRange(args).advance(2), ";"); this->Makefile->AddDefinition(listName, listString.c_str()); return true; diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 05d8ab5..35956ad 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -3016,13 +3016,7 @@ cmLocalGenerator::ConvertToRelativePath(const std::vector& local, { relative += "/"; } - const char* sep = ""; - for(unsigned int i=common; i < remote.size(); ++i) - { - relative += sep; - relative += remote[i]; - sep = "/"; - } + relative += cmJoin(cmRange(remote).advance(common), "/"); // Finally return the path. return relative; diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index 676e082..8f6364d 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -172,12 +172,7 @@ bool cmMacroHelperCommand::InvokeInitialPass } std::vector::const_iterator eit = expandedArgs.begin() + (this->Args.size() - 1); - const char* sep = ""; - for( ; eit != expandedArgs.end(); ++eit) - { - argnDef += sep + *eit; - sep = ";"; - } + argnDef += cmJoin(cmRange(eit, expandedArgs.end()), ";"); } argnDefInitialized = true; } diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 5260cb0..5c93975 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -406,12 +406,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) // Clock command else if (args[1] == "time" && args.size() > 2) { - std::string command = args[2]; - for (std::string::size_type cc = 3; cc < args.size(); cc ++) - { - command += " "; - command += args[cc]; - } + std::string command = cmJoin(cmRange(args).advance(2), " "); clock_t clock_start, clock_finish; time_t time_start, time_finish; @@ -473,14 +468,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) } std::string command = "\""; - command += args[3]; + command += cmJoin(cmRange(args).advance(3), "\" \""); command += "\""; - for (std::string::size_type cc = 4; cc < args.size(); cc ++) - { - command += " \""; - command += args[cc]; - command += "\""; - } int retval = 0; int timeout = 0; if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, &retval, -- cgit v0.12 From 0ea719326ea78b423a5ec95b1218b626e9392f07 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 14 Jan 2015 22:23:41 +0100 Subject: cmFindBase: Replace loop with cmJoin on range. --- Source/cmFindBase.cxx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx index 69991d5..6e55533 100644 --- a/Source/cmFindBase.cxx +++ b/Source/cmFindBase.cxx @@ -166,11 +166,9 @@ bool cmFindBase::ParseArguments(std::vector const& argsIn) } else { - this->VariableDocumentation += "one of the " + this->Names[0]; - for (unsigned int j = 1; j < this->Names.size() - 1; ++j) - { - this->VariableDocumentation += ", " + this->Names[j]; - } + this->VariableDocumentation += "one of the "; + this->VariableDocumentation += cmJoin(cmRange(this->Names).retreat(1), + ", "); this->VariableDocumentation += " or " + this->Names[this->Names.size() - 1] + " libraries be found"; } -- cgit v0.12 From 559dc15589ad0b9a7bdaa62ac7552899993f6f0d Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 10 Feb 2015 23:26:58 +0100 Subject: cmSet: Replace loop with cmJoin. --- Source/cmSetCommand.cxx | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/Source/cmSetCommand.cxx b/Source/cmSetCommand.cxx index 90d7b03..204d95b 100644 --- a/Source/cmSetCommand.cxx +++ b/Source/cmSetCommand.cxx @@ -108,17 +108,7 @@ bool cmSetCommand } // collect any values into a single semi-colon separated value list - if(static_cast(args.size()) > - static_cast(1 + ignoreLastArgs)) - { - value = args[1]; - size_t endPos = args.size() - ignoreLastArgs; - for(size_t i = 2; i < endPos; ++i) - { - value += ";"; - value += args[i]; - } - } + value = cmJoin(cmRange(args).advance(1).retreat(ignoreLastArgs), ";"); if (parentScope) { -- cgit v0.12 From e21f7829a2891ce7599ade02d4fd9c193657069a Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 10 Feb 2015 22:48:02 +0100 Subject: cmTarget: Use a sorted vector in place of a set. The vector has a more easy-to-use API. Join the string with cmJoin, and avoid erasing from the container in the loop. --- Source/cmTarget.cxx | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index f0bdea7..526a923 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -6687,40 +6687,33 @@ void cmTarget::CheckPropertyCompatibility(cmComputeLinkInformation *info, if (!prop.empty()) { - // Use a std::set to keep the error message sorted. - std::set props; + // Use a sorted std::vector to keep the error message sorted. + std::vector props; std::set::const_iterator i = emittedBools.find(prop); if (i != emittedBools.end()) { - props.insert(strBool); + props.push_back(strBool); } i = emittedStrings.find(prop); if (i != emittedStrings.end()) { - props.insert(strString); + props.push_back(strString); } i = emittedMinNumbers.find(prop); if (i != emittedMinNumbers.end()) { - props.insert(strNumMin); + props.push_back(strNumMin); } i = emittedMaxNumbers.find(prop); if (i != emittedMaxNumbers.end()) { - props.insert(strNumMax); + props.push_back(strNumMax); } + std::sort(props.begin(), props.end()); + + std::string propsString = cmJoin(cmRange(props).retreat(1), ", "); + propsString += " and the " + props.back(); - std::string propsString = *props.begin(); - props.erase(props.begin()); - while (props.size() > 1) - { - propsString += ", " + *props.begin(); - props.erase(props.begin()); - } - if (props.size() == 1) - { - propsString += " and the " + *props.begin(); - } std::ostringstream e; e << "Property \"" << prop << "\" appears in both the " << propsString << -- cgit v0.12 From 0b61b86df856e3cec366f8c23f35aae576b2d821 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 23 Jan 2015 01:03:45 +0100 Subject: Handle last element outside of the loop. There is no point in checking on each loop iteration whether it is the last element. --- Source/cmLocalUnixMakefileGenerator3.cxx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 54d330f..32da821 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -2298,10 +2298,9 @@ cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(const char* p, // Now add the rest of the components separated by the proper slash // direction for this platform. bool first = true; - for(unsigned int i=1; i < components.size(); ++i) + for(unsigned int i=1; i < components.size() - 1; ++i) { - // Only the last component can be empty to avoid double slashes. - if(!components[i].empty() || (i == (components.size()-1))) + if(!components[i].empty()) { if(!first) { @@ -2311,6 +2310,15 @@ cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(const char* p, first = false; } } + if (components.size() > 1) + { + // Only the last component can be empty to avoid double slashes. + if(!first) + { + result += slash; + } + result += components.back(); + } } // Close the quoted result. -- cgit v0.12 From abfca97525be06e067981b6c6bf63ba7a3aa52f9 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 10 Feb 2015 23:09:03 +0100 Subject: Move loop inside of condition. The loop is only executed if the condition is true. --- Source/cmLocalUnixMakefileGenerator3.cxx | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 32da821..703ab27 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -2295,23 +2295,23 @@ cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(const char* p, // Begin the quoted result with the root component. result += components[0]; - // Now add the rest of the components separated by the proper slash - // direction for this platform. - bool first = true; - for(unsigned int i=1; i < components.size() - 1; ++i) + if (components.size() > 1) { - if(!components[i].empty()) + // Now add the rest of the components separated by the proper slash + // direction for this platform. + bool first = true; + for(unsigned int i=1; i < components.size() - 1; ++i) { - if(!first) + if(!components[i].empty()) { - result += slash; + if(!first) + { + result += slash; + } + result += components[i]; + first = false; } - result += components[i]; - first = false; } - } - if (components.size() > 1) - { // Only the last component can be empty to avoid double slashes. if(!first) { -- cgit v0.12 From 8a399c8c9f1c4a793289d6baf37081efac082eee Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 23 Jan 2015 01:06:40 +0100 Subject: Convert loop to the common pattern. --- Source/cmLocalUnixMakefileGenerator3.cxx | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 703ab27..359141a 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -2299,24 +2299,18 @@ cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(const char* p, { // Now add the rest of the components separated by the proper slash // direction for this platform. - bool first = true; + const char* sep = ""; for(unsigned int i=1; i < components.size() - 1; ++i) { if(!components[i].empty()) { - if(!first) - { - result += slash; - } + result += sep; result += components[i]; - first = false; + sep = slash; } } // Only the last component can be empty to avoid double slashes. - if(!first) - { - result += slash; - } + result += slash; result += components.back(); } } -- cgit v0.12 From 7c3f637680ac0cdb6cec5e75ba4a9b188de5017b Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 24 Jan 2015 18:07:37 +0100 Subject: Convert loop into two algorithms. --- Source/cmLocalUnixMakefileGenerator3.cxx | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 359141a..a08c159 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -2299,16 +2299,12 @@ cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(const char* p, { // Now add the rest of the components separated by the proper slash // direction for this platform. - const char* sep = ""; - for(unsigned int i=1; i < components.size() - 1; ++i) - { - if(!components[i].empty()) - { - result += sep; - result += components[i]; - sep = slash; - } - } + std::vector::const_iterator compEnd + = std::remove(components.begin() + 1, components.end() - 1, + std::string()); + std::vector::const_iterator compStart + = components.begin() + 1; + result += cmJoin(cmRange(compStart, compEnd), slash); // Only the last component can be empty to avoid double slashes. result += slash; result += components.back(); -- cgit v0.12