From ebae5a302f9764ef04fc3bfa991ae0754ac448c5 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Mon, 10 Jun 2024 23:36:49 +0900 Subject: [PATCH] Prefer std::string::clear where possible (#2467) This is somewhat more clear and is declared noexcept. --- src/curl.cpp | 12 ++++++------ src/fdcache.cpp | 2 +- src/fdcache_entity.cpp | 10 +++++----- src/fdcache_fdinfo.cpp | 2 +- src/s3fs.cpp | 8 ++++---- src/s3fs_cred.cpp | 2 +- src/s3objlist.cpp | 6 +++--- src/types.h | 2 +- test/write_multiblock.cc | 2 +- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/curl.cpp b/src/curl.cpp index 3ad7e6c..cac9739 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -885,17 +885,17 @@ bool S3fsCurl::FinalCheckSse() { switch(S3fsCurl::ssetype){ case sse_type_t::SSE_DISABLE: - S3fsCurl::ssekmsid.erase(); + S3fsCurl::ssekmsid.clear(); return true; case sse_type_t::SSE_S3: - S3fsCurl::ssekmsid.erase(); + S3fsCurl::ssekmsid.clear(); return true; case sse_type_t::SSE_C: if(S3fsCurl::sseckeys.empty()){ S3FS_PRN_ERR("sse type is SSE-C, but there is no custom key."); return false; } - S3fsCurl::ssekmsid.erase(); + S3fsCurl::ssekmsid.clear(); return true; case sse_type_t::SSE_KMS: if(S3fsCurl::ssekmsid.empty()){ @@ -3091,7 +3091,7 @@ int S3fsCurl::GetIAMv2ApiToken(const char* token_url, int token_ttl, const char* S3FS_PRN_ERR("IAMv2 token url(%s) or ttl_hdr(%s) parameter are wrong.", token_url ? token_url : "null", token_ttl_hdr ? token_ttl_hdr : "null"); return -EIO; } - response.erase(); + response.clear(); url = token_url; if(!CreateCurlHandle()){ return -EIO; @@ -3154,7 +3154,7 @@ bool S3fsCurl::GetIAMCredentials(const char* cred_url, const char* iam_v2_token, return false; } url = cred_url; - response.erase(); + response.clear(); // at first set type for handle type = REQTYPE::IAMCRED; @@ -3240,7 +3240,7 @@ bool S3fsCurl::GetIAMRoleFromMetaData(const char* cred_url, const char* iam_v2_t return false; } url = cred_url; - token.erase(); + token.clear(); S3FS_PRN_INFO3("Get IAM Role name"); diff --git a/src/fdcache.cpp b/src/fdcache.cpp index 913ab33..8a7db1b 100644 --- a/src/fdcache.cpp +++ b/src/fdcache.cpp @@ -105,7 +105,7 @@ bool FdManager::SetCacheDir(const char* dir) bool FdManager::SetCacheCheckOutput(const char* path) { if(!path || '\0' == path[0]){ - check_cache_output.erase(); + check_cache_output.clear(); }else{ check_cache_output = path; } diff --git a/src/fdcache_entity.cpp b/src/fdcache_entity.cpp index 68069c3..bfcfca7 100644 --- a/src/fdcache_entity.cpp +++ b/src/fdcache_entity.cpp @@ -180,7 +180,7 @@ void FdEntity::Clear() if(-1 == unlink(mirrorpath.c_str())){ S3FS_PRN_WARN("failed to remove mirror cache file(%s) by errno(%d).", mirrorpath.c_str(), errno); } - mirrorpath.erase(); + mirrorpath.clear(); } } pagelist.Init(0, false, false); @@ -250,7 +250,7 @@ void FdEntity::Close(int fd) if(-1 == unlink(mirrorpath.c_str())){ S3FS_PRN_WARN("failed to remove mirror cache file(%s) by errno(%d).", mirrorpath.c_str(), errno); } - mirrorpath.erase(); + mirrorpath.clear(); } } } @@ -764,7 +764,7 @@ bool FdEntity::RenamePath(const std::string& newpath, std::string& fentmapkey) }else{ // does not have cache path - fentmapkey.erase(); + fentmapkey.clear(); FdManager::MakeRandomTempPath(newpath.c_str(), fentmapkey); } // set new path @@ -1156,8 +1156,8 @@ int FdEntity::NoCacheLoadAndPost(PseudoFdInfo* pseudo_obj, off_t start, off_t si // remove cache files(and cache stat file) FdManager::DeleteCacheFile(path.c_str()); // cache file path does not use no more. - cachepath.erase(); - mirrorpath.erase(); + cachepath.clear(); + mirrorpath.clear(); } // Change entity key in manager mapping diff --git a/src/fdcache_fdinfo.cpp b/src/fdcache_fdinfo.cpp index 3cbf376..3494dcc 100644 --- a/src/fdcache_fdinfo.cpp +++ b/src/fdcache_fdinfo.cpp @@ -251,7 +251,7 @@ bool PseudoFdInfo::ResetUploadInfo(AutoLock::Type type) { AutoLock auto_lock(&upload_list_lock, type); - upload_id.erase(); + upload_id.clear(); upload_list.clear(); instruct_count = 0; completed_count = 0; diff --git a/src/s3fs.cpp b/src/s3fs.cpp index 3b788d2..12fa2f3 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -902,7 +902,7 @@ bool get_object_sse_type(const char* path, sse_type_t& ssetype, std::string& sse } ssetype = sse_type_t::SSE_DISABLE; - ssevalue.erase(); + ssevalue.clear(); for(headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter){ std::string key = (*iter).first; if(0 == strcasecmp(key.c_str(), "x-amz-server-side-encryption") && 0 == strcasecmp((*iter).second.c_str(), "AES256")){ @@ -3601,7 +3601,7 @@ static bool get_meta_xattr_value(const char* path, std::string& rawvalue) } S3FS_PRN_DBG("[path=%s]", path); - rawvalue.erase(); + rawvalue.clear(); headers_t meta; if(0 != get_object_attribute(path, nullptr, &meta)){ @@ -3634,7 +3634,7 @@ static bool get_parent_meta_xattr_value(const char* path, std::string& rawvalue) static bool get_xattr_posix_key_value(const char* path, std::string& xattrvalue, bool default_key) { - xattrvalue.erase(); + xattrvalue.clear(); std::string rawvalue; if(!get_meta_xattr_value(path, rawvalue)){ @@ -3673,7 +3673,7 @@ static bool build_inherited_xattr_value(const char* path, std::string& xattrvalu { S3FS_PRN_DBG("[path=%s]", path); - xattrvalue.erase(); + xattrvalue.clear(); if(0 == strcmp(path, "/") || 0 == strcmp(path, ".")){ // path is mount point, thus does not have parent. diff --git a/src/s3fs_cred.cpp b/src/s3fs_cred.cpp index bce0c95..d7737d8 100644 --- a/src/s3fs_cred.cpp +++ b/src/s3fs_cred.cpp @@ -1175,7 +1175,7 @@ bool S3fsCred::CheckIAMCredentialUpdate(std::string* access_key_id, std::string* if(IsIBMIAMAuth() || IsSetExtCredLib() || is_ecs || is_use_session_token || IsSetIAMRole(AutoLock::ALREADY_LOCKED)){ *access_token = AWSAccessToken; }else{ - access_token->erase(); + access_token->clear(); } } diff --git a/src/s3objlist.cpp b/src/s3objlist.cpp index 4a3ed59..8df4e16 100644 --- a/src/s3objlist.cpp +++ b/src/s3objlist.cpp @@ -80,7 +80,7 @@ bool S3ObjList::insert(const char* name, const char* etag, bool is_dir) // Add object if(objects.end() != (iter = objects.find(newname))){ // Found same object --> update information. - (*iter).second.normalname.erase(); + (*iter).second.normalname.clear(); (*iter).second.orgname = orgname; (*iter).second.is_dir = is_dir; if(etag){ @@ -113,8 +113,8 @@ bool S3ObjList::insert_normalized(const char* name, const char* normalized, bool s3obj_t::iterator iter; if(objects.end() != (iter = objects.find(name))){ // found name --> over write - iter->second.orgname.erase(); - iter->second.etag.erase(); + iter->second.orgname.clear(); + iter->second.etag.clear(); iter->second.normalname = normalized; iter->second.is_dir = is_dir; }else{ diff --git a/src/types.h b/src/types.h index 4cb5ea6..a647e27 100644 --- a/src/types.h +++ b/src/types.h @@ -149,7 +149,7 @@ struct etagpair void clear() { - etag.erase(); + etag.clear(); part_num = -1; } }; diff --git a/test/write_multiblock.cc b/test/write_multiblock.cc index e77f98f..cffd4b0 100644 --- a/test/write_multiblock.cc +++ b/test/write_multiblock.cc @@ -109,7 +109,7 @@ static bool parse_string(const char* pstr, char delim, strlist_t& strlist) strAll = strAll.substr(pos + 1); }else{ strlist.push_back(strAll); - strAll.erase(); + strAll.clear(); } } return true;