mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-06-06 11:00:49 +00:00
Pass by value to trim functions (#2345)
These already force a copy so passing by value has the same performance but is simpler. But this allows the compiler to perform copy elision on temporaries and the caller to explicitly std::move in others.
This commit is contained in:
parent
2e4a6928c3
commit
e5b15bed7d
|
@ -105,15 +105,13 @@ std::string lower(std::string s)
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string trim_left(const std::string &s, const char *t /* = SPACES */)
|
std::string trim_left(std::string d, const char *t /* = SPACES */)
|
||||||
{
|
{
|
||||||
std::string d(s);
|
return d.erase(0, d.find_first_not_of(t));
|
||||||
return d.erase(0, s.find_first_not_of(t));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string trim_right(const std::string &s, const char *t /* = SPACES */)
|
std::string trim_right(std::string d, const char *t /* = SPACES */)
|
||||||
{
|
{
|
||||||
std::string d(s);
|
|
||||||
std::string::size_type i(d.find_last_not_of(t));
|
std::string::size_type i(d.find_last_not_of(t));
|
||||||
if(i == std::string::npos){
|
if(i == std::string::npos){
|
||||||
return "";
|
return "";
|
||||||
|
@ -122,9 +120,9 @@ std::string trim_right(const std::string &s, const char *t /* = SPACES */)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string trim(const std::string &s, const char *t /* = SPACES */)
|
std::string trim(std::string s, const char *t /* = SPACES */)
|
||||||
{
|
{
|
||||||
return trim_left(trim_right(s, t), t);
|
return trim_left(trim_right(std::move(s), t), t);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -75,9 +75,9 @@ off_t cvt_strtoofft(const char* str, int base);
|
||||||
//
|
//
|
||||||
// String Manipulation
|
// String Manipulation
|
||||||
//
|
//
|
||||||
std::string trim_left(const std::string &s, const char *t = SPACES);
|
std::string trim_left(std::string s, const char *t = SPACES);
|
||||||
std::string trim_right(const std::string &s, const char *t = SPACES);
|
std::string trim_right(std::string s, const char *t = SPACES);
|
||||||
std::string trim(const std::string &s, const char *t = SPACES);
|
std::string trim(std::string s, const char *t = SPACES);
|
||||||
std::string lower(std::string s);
|
std::string lower(std::string s);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue
Block a user