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 6628527
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/curl.h
Expand Up @@ -84,7 +84,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
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: 1 addition & 1 deletion src/mpu_util.h
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/s3objlist.h
Expand Up @@ -39,7 +39,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
2 changes: 1 addition & 1 deletion src/threadpoolman.h
Expand Up @@ -50,7 +50,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 6628527

Please sign in to comment.