Prefer std::string::clear where possible (#2467)

This is somewhat more clear and is declared noexcept.
This commit is contained in:
Andrew Gaul 2024-06-10 23:36:49 +09:00 committed by GitHub
parent ba7b2ef9f0
commit ebae5a302f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 23 additions and 23 deletions

View File

@ -885,17 +885,17 @@ bool S3fsCurl::FinalCheckSse()
{ {
switch(S3fsCurl::ssetype){ switch(S3fsCurl::ssetype){
case sse_type_t::SSE_DISABLE: case sse_type_t::SSE_DISABLE:
S3fsCurl::ssekmsid.erase(); S3fsCurl::ssekmsid.clear();
return true; return true;
case sse_type_t::SSE_S3: case sse_type_t::SSE_S3:
S3fsCurl::ssekmsid.erase(); S3fsCurl::ssekmsid.clear();
return true; return true;
case sse_type_t::SSE_C: case sse_type_t::SSE_C:
if(S3fsCurl::sseckeys.empty()){ if(S3fsCurl::sseckeys.empty()){
S3FS_PRN_ERR("sse type is SSE-C, but there is no custom key."); S3FS_PRN_ERR("sse type is SSE-C, but there is no custom key.");
return false; return false;
} }
S3fsCurl::ssekmsid.erase(); S3fsCurl::ssekmsid.clear();
return true; return true;
case sse_type_t::SSE_KMS: case sse_type_t::SSE_KMS:
if(S3fsCurl::ssekmsid.empty()){ 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"); 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; return -EIO;
} }
response.erase(); response.clear();
url = token_url; url = token_url;
if(!CreateCurlHandle()){ if(!CreateCurlHandle()){
return -EIO; return -EIO;
@ -3154,7 +3154,7 @@ bool S3fsCurl::GetIAMCredentials(const char* cred_url, const char* iam_v2_token,
return false; return false;
} }
url = cred_url; url = cred_url;
response.erase(); response.clear();
// at first set type for handle // at first set type for handle
type = REQTYPE::IAMCRED; type = REQTYPE::IAMCRED;
@ -3240,7 +3240,7 @@ bool S3fsCurl::GetIAMRoleFromMetaData(const char* cred_url, const char* iam_v2_t
return false; return false;
} }
url = cred_url; url = cred_url;
token.erase(); token.clear();
S3FS_PRN_INFO3("Get IAM Role name"); S3FS_PRN_INFO3("Get IAM Role name");

View File

@ -105,7 +105,7 @@ bool FdManager::SetCacheDir(const char* dir)
bool FdManager::SetCacheCheckOutput(const char* path) bool FdManager::SetCacheCheckOutput(const char* path)
{ {
if(!path || '\0' == path[0]){ if(!path || '\0' == path[0]){
check_cache_output.erase(); check_cache_output.clear();
}else{ }else{
check_cache_output = path; check_cache_output = path;
} }

View File

@ -180,7 +180,7 @@ void FdEntity::Clear()
if(-1 == unlink(mirrorpath.c_str())){ if(-1 == unlink(mirrorpath.c_str())){
S3FS_PRN_WARN("failed to remove mirror cache file(%s) by errno(%d).", mirrorpath.c_str(), errno); 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); pagelist.Init(0, false, false);
@ -250,7 +250,7 @@ void FdEntity::Close(int fd)
if(-1 == unlink(mirrorpath.c_str())){ if(-1 == unlink(mirrorpath.c_str())){
S3FS_PRN_WARN("failed to remove mirror cache file(%s) by errno(%d).", mirrorpath.c_str(), errno); 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{ }else{
// does not have cache path // does not have cache path
fentmapkey.erase(); fentmapkey.clear();
FdManager::MakeRandomTempPath(newpath.c_str(), fentmapkey); FdManager::MakeRandomTempPath(newpath.c_str(), fentmapkey);
} }
// set new path // 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) // remove cache files(and cache stat file)
FdManager::DeleteCacheFile(path.c_str()); FdManager::DeleteCacheFile(path.c_str());
// cache file path does not use no more. // cache file path does not use no more.
cachepath.erase(); cachepath.clear();
mirrorpath.erase(); mirrorpath.clear();
} }
// Change entity key in manager mapping // Change entity key in manager mapping

View File

@ -251,7 +251,7 @@ bool PseudoFdInfo::ResetUploadInfo(AutoLock::Type type)
{ {
AutoLock auto_lock(&upload_list_lock, type); AutoLock auto_lock(&upload_list_lock, type);
upload_id.erase(); upload_id.clear();
upload_list.clear(); upload_list.clear();
instruct_count = 0; instruct_count = 0;
completed_count = 0; completed_count = 0;

View File

@ -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; ssetype = sse_type_t::SSE_DISABLE;
ssevalue.erase(); ssevalue.clear();
for(headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter){ for(headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter){
std::string key = (*iter).first; std::string key = (*iter).first;
if(0 == strcasecmp(key.c_str(), "x-amz-server-side-encryption") && 0 == strcasecmp((*iter).second.c_str(), "AES256")){ 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); S3FS_PRN_DBG("[path=%s]", path);
rawvalue.erase(); rawvalue.clear();
headers_t meta; headers_t meta;
if(0 != get_object_attribute(path, nullptr, &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) static bool get_xattr_posix_key_value(const char* path, std::string& xattrvalue, bool default_key)
{ {
xattrvalue.erase(); xattrvalue.clear();
std::string rawvalue; std::string rawvalue;
if(!get_meta_xattr_value(path, 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); S3FS_PRN_DBG("[path=%s]", path);
xattrvalue.erase(); xattrvalue.clear();
if(0 == strcmp(path, "/") || 0 == strcmp(path, ".")){ if(0 == strcmp(path, "/") || 0 == strcmp(path, ".")){
// path is mount point, thus does not have parent. // path is mount point, thus does not have parent.

View File

@ -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)){ if(IsIBMIAMAuth() || IsSetExtCredLib() || is_ecs || is_use_session_token || IsSetIAMRole(AutoLock::ALREADY_LOCKED)){
*access_token = AWSAccessToken; *access_token = AWSAccessToken;
}else{ }else{
access_token->erase(); access_token->clear();
} }
} }

View File

@ -80,7 +80,7 @@ bool S3ObjList::insert(const char* name, const char* etag, bool is_dir)
// Add object // Add object
if(objects.end() != (iter = objects.find(newname))){ if(objects.end() != (iter = objects.find(newname))){
// Found same object --> update information. // Found same object --> update information.
(*iter).second.normalname.erase(); (*iter).second.normalname.clear();
(*iter).second.orgname = orgname; (*iter).second.orgname = orgname;
(*iter).second.is_dir = is_dir; (*iter).second.is_dir = is_dir;
if(etag){ if(etag){
@ -113,8 +113,8 @@ bool S3ObjList::insert_normalized(const char* name, const char* normalized, bool
s3obj_t::iterator iter; s3obj_t::iterator iter;
if(objects.end() != (iter = objects.find(name))){ if(objects.end() != (iter = objects.find(name))){
// found name --> over write // found name --> over write
iter->second.orgname.erase(); iter->second.orgname.clear();
iter->second.etag.erase(); iter->second.etag.clear();
iter->second.normalname = normalized; iter->second.normalname = normalized;
iter->second.is_dir = is_dir; iter->second.is_dir = is_dir;
}else{ }else{

View File

@ -149,7 +149,7 @@ struct etagpair
void clear() void clear()
{ {
etag.erase(); etag.clear();
part_num = -1; part_num = -1;
} }
}; };

View File

@ -109,7 +109,7 @@ static bool parse_string(const char* pstr, char delim, strlist_t& strlist)
strAll = strAll.substr(pos + 1); strAll = strAll.substr(pos + 1);
}else{ }else{
strlist.push_back(strAll); strlist.push_back(strAll);
strAll.erase(); strAll.clear();
} }
} }
return true; return true;