Skip to content

Commit

Permalink
Convert most std::list to std::vector
Browse files Browse the repository at this point in the history
This tends to be more efficient due to fewer allocations.
  • Loading branch information
gaul committed Aug 4, 2023
1 parent b29f8d0 commit 5675609
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/addhead.h
Expand Up @@ -23,6 +23,7 @@

#include <memory>
#include <regex.h>
#include <vector>

#include "metaheader.h"

Expand Down
3 changes: 1 addition & 2 deletions src/curl.h
Expand Up @@ -22,7 +22,6 @@
#define S3FS_CURL_H_

#include <curl/curl.h>
#include <list>
#include <map>
#include <memory>
#include <vector>
Expand Down Expand Up @@ -84,7 +83,7 @@ class Semaphore;
typedef bool (*s3fscurl_lazy_setup)(S3fsCurl* s3fscurl);

typedef std::map<std::string, std::string> sseckeymap_t;
typedef std::list<sseckeymap_t> sseckeylist_t;
typedef std::vector<sseckeymap_t> sseckeylist_t;

// Class for lapping curl
//
Expand Down
1 change: 1 addition & 0 deletions src/curl_handlerpool.h
Expand Up @@ -23,6 +23,7 @@

#include <cassert>
#include <curl/curl.h>
#include <list>

//----------------------------------------------
// Typedefs
Expand Down
1 change: 1 addition & 0 deletions src/curl_multi.h
Expand Up @@ -22,6 +22,7 @@
#define S3FS_CURL_MULTI_H_

#include <memory>
#include <vector>

//----------------------------------------------
// Typedef
Expand Down
3 changes: 2 additions & 1 deletion src/fdcache_fdinfo.cpp
Expand Up @@ -18,6 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <errno.h>
Expand Down Expand Up @@ -394,7 +395,7 @@ bool PseudoFdInfo::InsertUploadPart(off_t start, off_t size, int part_num, bool
upload_list.emplace_back(false, physical_fd, start, size, is_copy, petag_entity);

// sort by part number
upload_list.sort(filepart_partnum_compare);
std::sort(upload_list.begin(), upload_list.end(), filepart_partnum_compare);

// set etag pointer
*ppetag = petag_entity;
Expand Down
4 changes: 2 additions & 2 deletions src/fdcache_page.h
Expand Up @@ -21,8 +21,8 @@
#ifndef S3FS_FDCACHE_PAGE_H_
#define S3FS_FDCACHE_PAGE_H_

#include <list>
#include <sys/types.h>
#include <vector>

//------------------------------------------------
// Symbols
Expand Down Expand Up @@ -61,7 +61,7 @@ struct fdpage
return (0 < bytes ? offset + bytes - 1 : 0);
}
};
typedef std::list<struct fdpage> fdpage_list_t;
typedef std::vector<struct fdpage> fdpage_list_t;

//------------------------------------------------
// Class PageList
Expand Down
2 changes: 2 additions & 0 deletions src/fdcache_pseudofd.h
Expand Up @@ -21,6 +21,8 @@
#ifndef S3FS_FDCACHE_PSEUDOFD_H_
#define S3FS_FDCACHE_PSEUDOFD_H_

#include <vector>

//------------------------------------------------
// Typdefs
//------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/mpu_util.h
Expand Up @@ -22,7 +22,7 @@
#define S3FS_MPU_UTIL_H_

#include <string>
#include <list>
#include <vector>

//-------------------------------------------------------------------
// Structure / Typedef
Expand All @@ -34,7 +34,7 @@ typedef struct incomplete_multipart_upload_info
std::string date;
}INCOMP_MPU_INFO;

typedef std::list<INCOMP_MPU_INFO> incomp_mpu_list_t;
typedef std::vector<INCOMP_MPU_INFO> incomp_mpu_list_t;

//-------------------------------------------------------------------
// enum for utility process mode
Expand Down
3 changes: 2 additions & 1 deletion src/s3fs.cpp
Expand Up @@ -3282,7 +3282,7 @@ static int readdir_multi_head(const char* path, const S3ObjList& head, void* buf
}

// Make single head request(with max).
for(s3obj_list_t::iterator iter = headlist.begin(); headlist.end() != iter; iter = headlist.erase(iter)){
for(s3obj_list_t::iterator iter = headlist.begin(); headlist.end() != iter; ++iter){
std::string disppath = path + (*iter);
std::string etag = head.GetETag((*iter).c_str());
struct stat st;
Expand Down Expand Up @@ -3312,6 +3312,7 @@ static int readdir_multi_head(const char* path, const S3ObjList& head, void* buf
continue;
}
}
headlist.clear();

// Multi request
if(0 != (result = curlmulti.Request())){
Expand Down
3 changes: 1 addition & 2 deletions src/s3objlist.h
Expand Up @@ -21,7 +21,6 @@
#ifndef S3FS_S3OBJLIST_H_
#define S3FS_S3OBJLIST_H_

#include <list>
#include <map>
#include <string>
#include <vector>
Expand All @@ -39,7 +38,7 @@ struct s3obj_entry{
};

typedef std::map<std::string, struct s3obj_entry> s3obj_t;
typedef std::list<std::string> s3obj_list_t;
typedef std::vector<std::string> s3obj_list_t;

//-------------------------------------------------------------------
// Class S3ObjList
Expand Down
5 changes: 4 additions & 1 deletion src/threadpoolman.h
Expand Up @@ -21,6 +21,9 @@
#ifndef S3FS_THREADPOOLMAN_H_
#define S3FS_THREADPOOLMAN_H_

#include <list>
#include <vector>

#include "psemaphore.h"

//------------------------------------------------
Expand Down Expand Up @@ -50,7 +53,7 @@ struct thpoolman_param

typedef std::list<thpoolman_param*> thpoolman_params_t;

typedef std::list<pthread_t> thread_list_t;
typedef std::vector<pthread_t> thread_list_t;

//------------------------------------------------
// Class ThreadPoolMan
Expand Down
11 changes: 6 additions & 5 deletions src/types.h
Expand Up @@ -172,11 +172,12 @@ struct etagpair
}
};

// Requires pointer stability and thus must be a list not a vector
typedef std::list<etagpair> etaglist_t;

struct petagpool
{
std::list<etagpair> petaglist;
std::vector<etagpair> petaglist;

~petagpool()
{
Expand Down Expand Up @@ -249,7 +250,7 @@ struct filepart
}
};

typedef std::list<filepart> filepart_list_t;
typedef std::vector<filepart> filepart_list_t;

//
// Each part information for Untreated parts
Expand Down Expand Up @@ -307,7 +308,7 @@ struct untreatedpart
}
};

typedef std::list<untreatedpart> untreated_list_t;
typedef std::vector<untreatedpart> untreated_list_t;

//
// Information on each part of multipart upload
Expand All @@ -321,7 +322,7 @@ struct mp_part
explicit mp_part(off_t set_start = 0, off_t set_size = 0, int part = 0) : start(set_start), size(set_size), part_num(part) {}
};

typedef std::list<struct mp_part> mp_part_list_t;
typedef std::vector<struct mp_part> mp_part_list_t;

inline off_t total_mp_part_list(const mp_part_list_t& mplist)
{
Expand All @@ -346,7 +347,7 @@ typedef std::map<std::string, std::string, case_insensitive_compare_func> mimes_
//-------------------------------------------------------------------
// Typedefs specialized for use
//-------------------------------------------------------------------
typedef std::list<std::string> readline_t;
typedef std::vector<std::string> readline_t;
typedef std::map<std::string, std::string> kvmap_t;
typedef std::map<std::string, kvmap_t> bucketkvmap_t;

Expand Down
7 changes: 4 additions & 3 deletions test/write_multiblock.cc
Expand Up @@ -22,8 +22,9 @@
#include <cstdlib>
#include <iostream>
#include <climits>
#include <string>
#include <list>
#include <string>
#include <vector>

#include <unistd.h>
#include <sys/types.h>
Expand All @@ -41,8 +42,8 @@ struct write_block_part
off_t size;
};

typedef std::list<write_block_part> wbpart_list_t;
typedef std::list<std::string> strlist_t;
typedef std::vector<write_block_part> wbpart_list_t;
typedef std::list<std::string> strlist_t;

//---------------------------------------------------------
// Const
Expand Down

0 comments on commit 5675609

Please sign in to comment.