mirror of
https://github.com/aristocratos/btop.git
synced 2024-05-29 16:50:20 +12:00
Avoid the unnecessary use of copy constructor
When you want to pass a `std::string` to `std::string_view`, prefer to do such operation during object initialization via `{}` so you can avoid to use the copy constructor, which can be expensive under certain situations.
This commit is contained in:
parent
2b02a6656f
commit
820391494b
|
@ -262,7 +262,7 @@ namespace Tools {
|
|||
}
|
||||
|
||||
string ltrim(const string& str, const string& t_str) {
|
||||
string_view str_v = str;
|
||||
string_view str_v{str};
|
||||
while (str_v.starts_with(t_str))
|
||||
str_v.remove_prefix(t_str.size());
|
||||
|
||||
|
@ -270,7 +270,7 @@ namespace Tools {
|
|||
}
|
||||
|
||||
string rtrim(const string& str, const string& t_str) {
|
||||
string_view str_v = str;
|
||||
string_view str_v{str};
|
||||
while (str_v.ends_with(t_str))
|
||||
str_v.remove_suffix(t_str.size());
|
||||
|
||||
|
|
Loading…
Reference in a new issue