Improve path splitting speed

And create a range closure so the components can be iterated without allocating a container.
This commit is contained in:
Marshall Mohror
2023-06-09 21:28:34 -05:00
parent b3e2c9f9f1
commit 8626140b73
6 changed files with 45 additions and 27 deletions

View File

@@ -350,17 +350,11 @@ std::string_view RemoveTrailingSlash(std::string_view path) {
}
std::vector<std::string> SplitPathComponents(std::string_view filename) {
std::string copy(filename);
std::replace(copy.begin(), copy.end(), '\\', '/');
std::vector<std::string> out;
std::stringstream stream(copy);
std::string item;
while (std::getline(stream, item, '/')) {
out.push_back(std::move(item));
std::vector<std::string> copied_components;
for (std::string_view component : filename | split_path_components_view) {
copied_components.emplace_back(component);
}
return out;
return copied_components;
}
std::string SanitizePath(std::string_view path_, DirectorySeparator directory_separator) {