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:
Στέφανος 2022-10-04 16:20:20 +03:00
parent 2b02a6656f
commit 820391494b

View file

@ -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());