Prefer find(char) over find(const char *)

The former can be faster.  Found via clang-tidy.
This commit is contained in:
Andrew Gaul 2019-01-17 20:24:24 -08:00
parent 25b49e1a2e
commit e29548178b
3 changed files with 11 additions and 11 deletions

View File

@ -2896,7 +2896,7 @@ static bool parse_xattr_keyval(const std::string& xattrpair, string& key, PXATTR
// parse key and value
size_t pos;
string tmpval;
if(string::npos == (pos = xattrpair.find_first_of(":"))){
if(string::npos == (pos = xattrpair.find_first_of(':'))){
S3FS_PRN_ERR("one of xattr pair(%s) is wrong format.", xattrpair.c_str());
return false;
}
@ -2927,8 +2927,8 @@ static size_t parse_xattrs(const std::string& strxattrs, xattrs_t& xattrs)
{
size_t startpos;
size_t endpos = string::npos;
if(string::npos != (startpos = jsonxattrs.find_first_of("{"))){
endpos = jsonxattrs.find_last_of("}");
if(string::npos != (startpos = jsonxattrs.find_first_of('{'))){
endpos = jsonxattrs.find_last_of('}');
}
if(startpos == string::npos || endpos == string::npos || endpos <= startpos){
S3FS_PRN_WARN("xattr header(%s) is not json format.", jsonxattrs.c_str());
@ -2938,7 +2938,7 @@ static size_t parse_xattrs(const std::string& strxattrs, xattrs_t& xattrs)
}
// parse each key:val
for(size_t pair_nextpos = restxattrs.find_first_of(","); 0 < restxattrs.length(); restxattrs = (pair_nextpos != string::npos ? restxattrs.substr(pair_nextpos + 1) : string("")), pair_nextpos = restxattrs.find_first_of(",")){
for(size_t pair_nextpos = restxattrs.find_first_of(','); 0 < restxattrs.length(); restxattrs = (pair_nextpos != string::npos ? restxattrs.substr(pair_nextpos + 1) : string("")), pair_nextpos = restxattrs.find_first_of(',')){
string pair = pair_nextpos != string::npos ? restxattrs.substr(0, pair_nextpos) : restxattrs;
string key = "";
PXATTRVAL pval = NULL;
@ -3862,7 +3862,7 @@ static int parse_passwd_file(bucketkvmap_t& resmap)
S3FS_PRN_EXIT("invalid line in passwd file, found whitespace character.");
return -1;
}
if(0 == line.find_first_of("[")){
if(0 == line.find_first_of('[')){
S3FS_PRN_EXIT("invalid line in passwd file, found a bracket \"[\" character.");
return -1;
}
@ -4953,7 +4953,7 @@ int main(int argc, char* argv[])
// get program name - emulate basename
program_name.assign(argv[0]);
size_t found = program_name.find_last_of("/");
size_t found = program_name.find_last_of('/');
if(found != string::npos){
program_name.replace(0, found+1, "");
}

View File

@ -283,7 +283,7 @@ bool S3ObjList::MakeHierarchizedList(s3obj_list_t& list, bool haveSlash)
h_map[strtmp] = true;
// check hierarchized directory
for(string::size_type pos = strtmp.find_last_of("/"); string::npos != pos; pos = strtmp.find_last_of("/")){
for(string::size_type pos = strtmp.find_last_of('/'); string::npos != pos; pos = strtmp.find_last_of('/')){
strtmp = strtmp.substr(0, pos);
if(0 == strtmp.length() || "/" == strtmp){
break;
@ -822,7 +822,7 @@ mode_t get_mode(headers_t& meta, const char* path, bool checkdir, bool forcedir)
if(meta.end() != (iter = meta.find("Content-Type"))){
string strConType = (*iter).second;
// Leave just the mime type, remove any optional parameters (eg charset)
string::size_type pos = strConType.find(";");
string::size_type pos = strConType.find(';');
if(string::npos != pos){
strConType = strConType.substr(0, pos);
}

View File

@ -210,15 +210,15 @@ bool takeout_str_dquart(string& str)
size_t pos;
// '"' for start
if(string::npos != (pos = str.find_first_of("\""))){
if(string::npos != (pos = str.find_first_of('\"'))){
str = str.substr(pos + 1);
// '"' for end
if(string::npos == (pos = str.find_last_of("\""))){
if(string::npos == (pos = str.find_last_of('\"'))){
return false;
}
str = str.substr(0, pos);
if(string::npos != str.find_first_of("\"")){
if(string::npos != str.find_first_of('\"')){
return false;
}
}