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.
This commit is contained in:
Ben Boeckel 2017-05-04 10:12:45 -04:00 committed by Brad King
parent ec526768ac
commit 3e027d9def
7 changed files with 24 additions and 24 deletions

View File

@ -7,8 +7,8 @@
#include "cmXMLParser.h"
#include <list>
#include <map>
#include <vector>
struct cmWIXPatchNode
{
@ -36,7 +36,7 @@ struct cmWIXPatchElement : cmWIXPatchNode
~cmWIXPatchElement();
typedef std::list<cmWIXPatchNode*> child_list_t;
typedef std::vector<cmWIXPatchNode*> child_list_t;
typedef std::map<std::string, std::string> attributes_t;
std::string name;
@ -84,7 +84,7 @@ private:
fragment_map_t& Fragments;
std::list<cmWIXPatchElement*> ElementStack;
std::vector<cmWIXPatchElement*> ElementStack;
};
#endif

View File

@ -6,7 +6,6 @@
#include "cmsys/Glob.hxx"
#include "cmsys/RegularExpression.hxx"
#include <algorithm>
#include <list>
#include <utility>
#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<std::pair<std::string, std::string> > symlinkedFiles;
std::vector<std::pair<std::string, std::string> > 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<std::pair<std::string, std::string> >::iterator symlinkedIt;
std::vector<std::pair<std::string, std::string> >::iterator
symlinkedIt;
std::string curDir = cmSystemTools::GetCurrentWorkingDirectory();
std::string goToDir = tempDir;
goToDir += "/" + subdir;

View File

@ -103,8 +103,8 @@ bool cmCTestSVN::NoteOldRevision()
return false;
}
std::list<SVNInfo>::iterator itbeg = this->Repositories.begin();
std::list<SVNInfo>::iterator itend = this->Repositories.end();
std::vector<SVNInfo>::iterator itbeg = this->Repositories.begin();
std::vector<SVNInfo>::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<SVNInfo>::iterator itbeg = this->Repositories.begin();
std::list<SVNInfo>::iterator itend = this->Repositories.end();
std::vector<SVNInfo>::iterator itbeg = this->Repositories.begin();
std::vector<SVNInfo>::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<SVNInfo>::iterator itbeg = this->Repositories.begin();
std::list<SVNInfo>::iterator itend = this->Repositories.end();
std::vector<SVNInfo>::iterator itbeg = this->Repositories.begin();
std::vector<SVNInfo>::iterator itend = this->Repositories.end();
for (; itbeg != itend; itbeg++) {
SVNInfo& svninfo = *itbeg;
result = this->LoadRevisions(svninfo) && result;

View File

@ -8,7 +8,6 @@
#include "cmCTestGlobalVC.h"
#include <iosfwd>
#include <list>
#include <string>
#include <vector>
@ -71,7 +70,7 @@ private:
friend struct Revision;
// Info of all the repositories (root, externals and nested ones).
std::list<SVNInfo> Repositories;
std::vector<SVNInfo> Repositories;
// Pointer to the infos of the root repository.
SVNInfo* RootInfo;

View File

@ -10,11 +10,11 @@
#include "cmsys/String.hxx"
#include <algorithm>
#include <assert.h>
#include <list>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include "cmAlgorithms.h"
#include "cmCommandArgumentsHelper.h"
@ -2618,7 +2618,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
bool showProgress = false;
std::string userpwd;
std::list<std::string> curl_headers;
std::vector<std::string> curl_headers;
while (i != args.end()) {
if (*i == "TIMEOUT") {
@ -2862,7 +2862,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
}
struct curl_slist* headers = CM_NULLPTR;
for (std::list<std::string>::const_iterator h = curl_headers.begin();
for (std::vector<std::string>::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<std::string> const& args)
bool showProgress = false;
std::string userpwd;
std::list<std::string> curl_headers;
std::vector<std::string> curl_headers;
while (i != args.end()) {
if (*i == "TIMEOUT") {
@ -3120,7 +3120,7 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
}
struct curl_slist* headers = CM_NULLPTR;
for (std::list<std::string>::const_iterator h = curl_headers.begin();
for (std::vector<std::string>::const_iterator h = curl_headers.begin();
h != curl_headers.end(); ++h) {
headers = ::curl_slist_append(headers, h->c_str());
}

View File

@ -5,8 +5,8 @@
#include "cmConfigure.h"
#include <list>
#include <string>
#include <vector>
class cmFileLock;
class cmFileLockResult;
@ -70,14 +70,14 @@ private:
bool IsAlreadyLocked(const std::string& filename) const;
private:
typedef std::list<cmFileLock*> List;
typedef std::vector<cmFileLock*> List;
typedef List::iterator It;
typedef List::const_iterator CIt;
List Locks;
};
typedef std::list<ScopePool*> List;
typedef std::vector<ScopePool*> List;
typedef List::iterator It;
typedef List::const_iterator CIt;

View File

@ -12,6 +12,7 @@
#include "cmsys/Encoding.hxx"
#include <assert.h>
#include <vector>
#include <windows.h>
static cmVS7FlagTable cmVS7ExtraFlagTable[] = {
@ -680,10 +681,10 @@ std::set<std::string> cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
// default build if another target depends on it
int type = target->GetType();
if (type == cmStateEnums::GLOBAL_TARGET) {
std::list<std::string> targetNames;
std::vector<std::string> targetNames;
targetNames.push_back("INSTALL");
targetNames.push_back("PACKAGE");
for (std::list<std::string>::const_iterator t = targetNames.begin();
for (std::vector<std::string>::const_iterator t = targetNames.begin();
t != targetNames.end(); ++t) {
// check if target <*t> is part of default build
if (target->GetName() == *t) {