util: reserve space in normalize_path()

Pessimistic reservations to ensure that it does not need to be
reallocated.
This commit is contained in:
Max Kellermann 2020-01-31 12:05:47 +01:00
parent 5c0c336c6b
commit 53c4e30024

View file

@ -1557,11 +1557,13 @@ string normalize_path(const std::string_view path)
size_t n; size_t n;
vector<string> components, final_components; vector<string> components, final_components;
string new_path; string new_path;
new_path.reserve(path.size());
if ( !path.empty() && path[0] == '/' ) if ( !path.empty() && path[0] == '/' )
new_path = "/"; new_path = "/";
tokenize_string(path, "/", &components); tokenize_string(path, "/", &components);
final_components.reserve(components.size());
vector<string>::const_iterator it; vector<string>::const_iterator it;
for ( it = components.begin(); it != components.end(); ++it ) for ( it = components.begin(); it != components.end(); ++it )