util: pass std::string_view to normalize_path()

Reduce overhead in some callers.
This commit is contained in:
Max Kellermann 2020-01-31 13:25:34 +01:00
parent f1566bda14
commit 0589f295fa
2 changed files with 3 additions and 3 deletions

View file

@ -1552,13 +1552,13 @@ TEST_CASE("util normalize_path")
CHECK(normalize_path("zeek/../..") == ".."); CHECK(normalize_path("zeek/../..") == "..");
} }
string normalize_path(const string& path) 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;
if ( path[0] == '/' ) if ( !path.empty() && path[0] == '/' )
new_path = "/"; new_path = "/";
tokenize_string(path, "/", &components); tokenize_string(path, "/", &components);

View file

@ -344,7 +344,7 @@ std::string flatten_script_name(const std::string& name,
* @param path A filesystem path. * @param path A filesystem path.
* @return A canonical/shortened version of \a path. * @return A canonical/shortened version of \a path.
*/ */
std::string normalize_path(const std::string& path); std::string normalize_path(std::string_view path);
/** /**
* Strip the ZEEKPATH component from a path. * Strip the ZEEKPATH component from a path.