From 3e027d9def0f2d9f542cb71eda12e9527c418c9e Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 4 May 2017 10:12:45 -0400 Subject: c++: prefer vectors over lists None of these usages of `std::list` were inserting or removing elements in the middle of the structure, so there were no benefits to using it. Other uses were related to C pointers being stable in a list of strings whereas in a vector of strings, small pointer optimizations could be moved and become invalid after a modification to the hosting vector. None of these uses modified the vector after handing out a C string to an external store. --- Source/CPack/WiX/cmWIXPatchParser.h | 6 +++--- Source/CPack/cmCPackGenerator.cxx | 6 +++--- Source/CTest/cmCTestSVN.cxx | 12 ++++++------ Source/CTest/cmCTestSVN.h | 3 +-- Source/cmFileCommand.cxx | 10 +++++----- Source/cmFileLockPool.h | 6 +++--- Source/cmGlobalVisualStudio7Generator.cxx | 5 +++-- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Source/CPack/WiX/cmWIXPatchParser.h b/Source/CPack/WiX/cmWIXPatchParser.h index c0c96cd..52c7e35 100644 --- a/Source/CPack/WiX/cmWIXPatchParser.h +++ b/Source/CPack/WiX/cmWIXPatchParser.h @@ -7,8 +7,8 @@ #include "cmXMLParser.h" -#include #include +#include struct cmWIXPatchNode { @@ -36,7 +36,7 @@ struct cmWIXPatchElement : cmWIXPatchNode ~cmWIXPatchElement(); - typedef std::list child_list_t; + typedef std::vector child_list_t; typedef std::map attributes_t; std::string name; @@ -84,7 +84,7 @@ private: fragment_map_t& Fragments; - std::list ElementStack; + std::vector ElementStack; }; #endif diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index a95ca76..c5495c6 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -6,7 +6,6 @@ #include "cmsys/Glob.hxx" #include "cmsys/RegularExpression.hxx" #include -#include #include #include "cmCPackComponentGroup.h" @@ -314,7 +313,7 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories( const std::string& tempDir = tempInstallDirectory; for (it = installDirectoriesVector.begin(); it != installDirectoriesVector.end(); ++it) { - std::list > symlinkedFiles; + std::vector > symlinkedFiles; cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl); cmsys::Glob gl; std::string top = *it; @@ -378,7 +377,8 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories( } /* rebuild symlinks in the installed tree */ if (!symlinkedFiles.empty()) { - std::list >::iterator symlinkedIt; + std::vector >::iterator + symlinkedIt; std::string curDir = cmSystemTools::GetCurrentWorkingDirectory(); std::string goToDir = tempDir; goToDir += "/" + subdir; diff --git a/Source/CTest/cmCTestSVN.cxx b/Source/CTest/cmCTestSVN.cxx index 0b87281..f60f78c 100644 --- a/Source/CTest/cmCTestSVN.cxx +++ b/Source/CTest/cmCTestSVN.cxx @@ -103,8 +103,8 @@ bool cmCTestSVN::NoteOldRevision() return false; } - std::list::iterator itbeg = this->Repositories.begin(); - std::list::iterator itend = this->Repositories.end(); + std::vector::iterator itbeg = this->Repositories.begin(); + std::vector::iterator itend = this->Repositories.end(); for (; itbeg != itend; itbeg++) { SVNInfo& svninfo = *itbeg; svninfo.OldRevision = this->LoadInfo(svninfo); @@ -127,8 +127,8 @@ bool cmCTestSVN::NoteNewRevision() return false; } - std::list::iterator itbeg = this->Repositories.begin(); - std::list::iterator itend = this->Repositories.end(); + std::vector::iterator itbeg = this->Repositories.begin(); + std::vector::iterator itend = this->Repositories.end(); for (; itbeg != itend; itbeg++) { SVNInfo& svninfo = *itbeg; svninfo.NewRevision = this->LoadInfo(svninfo); @@ -380,8 +380,8 @@ bool cmCTestSVN::LoadRevisions() { bool result = true; // Get revisions for all the external repositories - std::list::iterator itbeg = this->Repositories.begin(); - std::list::iterator itend = this->Repositories.end(); + std::vector::iterator itbeg = this->Repositories.begin(); + std::vector::iterator itend = this->Repositories.end(); for (; itbeg != itend; itbeg++) { SVNInfo& svninfo = *itbeg; result = this->LoadRevisions(svninfo) && result; diff --git a/Source/CTest/cmCTestSVN.h b/Source/CTest/cmCTestSVN.h index d90d387..46b0778 100644 --- a/Source/CTest/cmCTestSVN.h +++ b/Source/CTest/cmCTestSVN.h @@ -8,7 +8,6 @@ #include "cmCTestGlobalVC.h" #include -#include #include #include @@ -71,7 +70,7 @@ private: friend struct Revision; // Info of all the repositories (root, externals and nested ones). - std::list Repositories; + std::vector Repositories; // Pointer to the infos of the root repository. SVNInfo* RootInfo; diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index fa166a0..2c25e9b 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -10,11 +10,11 @@ #include "cmsys/String.hxx" #include #include -#include #include #include #include #include +#include #include "cmAlgorithms.h" #include "cmCommandArgumentsHelper.h" @@ -2618,7 +2618,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector const& args) bool showProgress = false; std::string userpwd; - std::list curl_headers; + std::vector curl_headers; while (i != args.end()) { if (*i == "TIMEOUT") { @@ -2862,7 +2862,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector const& args) } struct curl_slist* headers = CM_NULLPTR; - for (std::list::const_iterator h = curl_headers.begin(); + for (std::vector::const_iterator h = curl_headers.begin(); h != curl_headers.end(); ++h) { headers = ::curl_slist_append(headers, h->c_str()); } @@ -2952,7 +2952,7 @@ bool cmFileCommand::HandleUploadCommand(std::vector const& args) bool showProgress = false; std::string userpwd; - std::list curl_headers; + std::vector curl_headers; while (i != args.end()) { if (*i == "TIMEOUT") { @@ -3120,7 +3120,7 @@ bool cmFileCommand::HandleUploadCommand(std::vector const& args) } struct curl_slist* headers = CM_NULLPTR; - for (std::list::const_iterator h = curl_headers.begin(); + for (std::vector::const_iterator h = curl_headers.begin(); h != curl_headers.end(); ++h) { headers = ::curl_slist_append(headers, h->c_str()); } diff --git a/Source/cmFileLockPool.h b/Source/cmFileLockPool.h index 689ddd7..c96a8c2 100644 --- a/Source/cmFileLockPool.h +++ b/Source/cmFileLockPool.h @@ -5,8 +5,8 @@ #include "cmConfigure.h" -#include #include +#include class cmFileLock; class cmFileLockResult; @@ -70,14 +70,14 @@ private: bool IsAlreadyLocked(const std::string& filename) const; private: - typedef std::list List; + typedef std::vector List; typedef List::iterator It; typedef List::const_iterator CIt; List Locks; }; - typedef std::list List; + typedef std::vector List; typedef List::iterator It; typedef List::const_iterator CIt; diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 1b75a08..f067d8f 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -12,6 +12,7 @@ #include "cmsys/Encoding.hxx" #include +#include #include static cmVS7FlagTable cmVS7ExtraFlagTable[] = { @@ -680,10 +681,10 @@ std::set cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild( // default build if another target depends on it int type = target->GetType(); if (type == cmStateEnums::GLOBAL_TARGET) { - std::list targetNames; + std::vector targetNames; targetNames.push_back("INSTALL"); targetNames.push_back("PACKAGE"); - for (std::list::const_iterator t = targetNames.begin(); + for (std::vector::const_iterator t = targetNames.begin(); t != targetNames.end(); ++t) { // check if target <*t> is part of default build if (target->GetName() == *t) { -- cgit v0.12