From 56756096707b18c26c1e1091f8d9a2f127ab3908 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Fri, 4 Aug 2023 09:49:43 +0900 Subject: [PATCH] Convert most std::list to std::vector This tends to be more efficient due to fewer allocations. --- src/addhead.h | 1 + src/curl.h | 3 +-- src/curl_handlerpool.h | 1 + src/curl_multi.h | 1 + src/fdcache_fdinfo.cpp | 3 ++- src/fdcache_page.h | 4 ++-- src/fdcache_pseudofd.h | 2 ++ src/mpu_util.h | 4 ++-- src/s3fs.cpp | 3 ++- src/s3objlist.h | 3 +-- src/threadpoolman.h | 5 ++++- src/types.h | 11 ++++++----- test/write_multiblock.cc | 7 ++++--- 13 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/addhead.h b/src/addhead.h index aba607aee2..4c55e0ad72 100644 --- a/src/addhead.h +++ b/src/addhead.h @@ -23,6 +23,7 @@ #include #include +#include #include "metaheader.h" diff --git a/src/curl.h b/src/curl.h index 097f4042bd..f57bb0c78f 100644 --- a/src/curl.h +++ b/src/curl.h @@ -22,7 +22,6 @@ #define S3FS_CURL_H_ #include -#include #include #include #include @@ -84,7 +83,7 @@ class Semaphore; typedef bool (*s3fscurl_lazy_setup)(S3fsCurl* s3fscurl); typedef std::map sseckeymap_t; -typedef std::list sseckeylist_t; +typedef std::vector sseckeylist_t; // Class for lapping curl // diff --git a/src/curl_handlerpool.h b/src/curl_handlerpool.h index eeee1c382d..419cf5ac2d 100644 --- a/src/curl_handlerpool.h +++ b/src/curl_handlerpool.h @@ -23,6 +23,7 @@ #include #include +#include //---------------------------------------------- // Typedefs diff --git a/src/curl_multi.h b/src/curl_multi.h index 6e5ba1ea1d..0778a6f072 100644 --- a/src/curl_multi.h +++ b/src/curl_multi.h @@ -22,6 +22,7 @@ #define S3FS_CURL_MULTI_H_ #include +#include //---------------------------------------------- // Typedef diff --git a/src/fdcache_fdinfo.cpp b/src/fdcache_fdinfo.cpp index 8a518ad5a5..a1f98d5d96 100644 --- a/src/fdcache_fdinfo.cpp +++ b/src/fdcache_fdinfo.cpp @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include #include #include #include @@ -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; diff --git a/src/fdcache_page.h b/src/fdcache_page.h index 7a1804ced8..e03a2ce96d 100644 --- a/src/fdcache_page.h +++ b/src/fdcache_page.h @@ -21,8 +21,8 @@ #ifndef S3FS_FDCACHE_PAGE_H_ #define S3FS_FDCACHE_PAGE_H_ -#include #include +#include //------------------------------------------------ // Symbols @@ -61,7 +61,7 @@ struct fdpage return (0 < bytes ? offset + bytes - 1 : 0); } }; -typedef std::list fdpage_list_t; +typedef std::vector fdpage_list_t; //------------------------------------------------ // Class PageList diff --git a/src/fdcache_pseudofd.h b/src/fdcache_pseudofd.h index 9dfadfa6fd..c4ff337a48 100644 --- a/src/fdcache_pseudofd.h +++ b/src/fdcache_pseudofd.h @@ -21,6 +21,8 @@ #ifndef S3FS_FDCACHE_PSEUDOFD_H_ #define S3FS_FDCACHE_PSEUDOFD_H_ +#include + //------------------------------------------------ // Typdefs //------------------------------------------------ diff --git a/src/mpu_util.h b/src/mpu_util.h index 2f6c24b2a9..ca60659175 100644 --- a/src/mpu_util.h +++ b/src/mpu_util.h @@ -22,7 +22,7 @@ #define S3FS_MPU_UTIL_H_ #include -#include +#include //------------------------------------------------------------------- // Structure / Typedef @@ -34,7 +34,7 @@ typedef struct incomplete_multipart_upload_info std::string date; }INCOMP_MPU_INFO; -typedef std::list incomp_mpu_list_t; +typedef std::vector incomp_mpu_list_t; //------------------------------------------------------------------- // enum for utility process mode diff --git a/src/s3fs.cpp b/src/s3fs.cpp index fd3ec08dd2..f2aadc8cfa 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -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; @@ -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())){ diff --git a/src/s3objlist.h b/src/s3objlist.h index aed1fa0fae..ffd2d9bb36 100644 --- a/src/s3objlist.h +++ b/src/s3objlist.h @@ -21,7 +21,6 @@ #ifndef S3FS_S3OBJLIST_H_ #define S3FS_S3OBJLIST_H_ -#include #include #include #include @@ -39,7 +38,7 @@ struct s3obj_entry{ }; typedef std::map s3obj_t; -typedef std::list s3obj_list_t; +typedef std::vector s3obj_list_t; //------------------------------------------------------------------- // Class S3ObjList diff --git a/src/threadpoolman.h b/src/threadpoolman.h index 99d1c8454e..469df7a037 100644 --- a/src/threadpoolman.h +++ b/src/threadpoolman.h @@ -21,6 +21,9 @@ #ifndef S3FS_THREADPOOLMAN_H_ #define S3FS_THREADPOOLMAN_H_ +#include +#include + #include "psemaphore.h" //------------------------------------------------ @@ -50,7 +53,7 @@ struct thpoolman_param typedef std::list thpoolman_params_t; -typedef std::list thread_list_t; +typedef std::vector thread_list_t; //------------------------------------------------ // Class ThreadPoolMan diff --git a/src/types.h b/src/types.h index 39103dc1f4..a9dd4987a9 100644 --- a/src/types.h +++ b/src/types.h @@ -172,11 +172,12 @@ struct etagpair } }; +// Requires pointer stability and thus must be a list not a vector typedef std::list etaglist_t; struct petagpool { - std::list petaglist; + std::vector petaglist; ~petagpool() { @@ -249,7 +250,7 @@ struct filepart } }; -typedef std::list filepart_list_t; +typedef std::vector filepart_list_t; // // Each part information for Untreated parts @@ -307,7 +308,7 @@ struct untreatedpart } }; -typedef std::list untreated_list_t; +typedef std::vector untreated_list_t; // // Information on each part of multipart upload @@ -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 mp_part_list_t; +typedef std::vector mp_part_list_t; inline off_t total_mp_part_list(const mp_part_list_t& mplist) { @@ -346,7 +347,7 @@ typedef std::map mimes_ //------------------------------------------------------------------- // Typedefs specialized for use //------------------------------------------------------------------- -typedef std::list readline_t; +typedef std::vector readline_t; typedef std::map kvmap_t; typedef std::map bucketkvmap_t; diff --git a/test/write_multiblock.cc b/test/write_multiblock.cc index bbcd775ae9..66d00ce4e5 100644 --- a/test/write_multiblock.cc +++ b/test/write_multiblock.cc @@ -22,8 +22,9 @@ #include #include #include -#include #include +#include +#include #include #include @@ -41,8 +42,8 @@ struct write_block_part off_t size; }; -typedef std::list wbpart_list_t; -typedef std::list strlist_t; +typedef std::vector wbpart_list_t; +typedef std::list strlist_t; //--------------------------------------------------------- // Const