Commit e2d2bb87 authored by Max Kellermann's avatar Max Kellermann

storage/Composite: use IterableSplitString()

parent a98d627c
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "CompositeStorage.hxx" #include "CompositeStorage.hxx"
#include "FileInfo.hxx" #include "FileInfo.hxx"
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "util/IterableSplitString.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"
#include <set> #include <set>
...@@ -95,8 +96,11 @@ const CompositeStorage::Directory * ...@@ -95,8 +96,11 @@ const CompositeStorage::Directory *
CompositeStorage::Directory::Find(std::string_view uri) const noexcept CompositeStorage::Directory::Find(std::string_view uri) const noexcept
{ {
const Directory *directory = this; const Directory *directory = this;
while (!uri.empty()) {
const auto name = NextSegment(uri); for (std::string_view name : IterableSplitString(uri, '/')) {
if (name.empty())
continue;
auto i = directory->children.find(name); auto i = directory->children.find(name);
if (i == directory->children.end()) if (i == directory->children.end())
return nullptr; return nullptr;
...@@ -111,8 +115,11 @@ CompositeStorage::Directory & ...@@ -111,8 +115,11 @@ CompositeStorage::Directory &
CompositeStorage::Directory::Make(std::string_view uri) CompositeStorage::Directory::Make(std::string_view uri)
{ {
Directory *directory = this; Directory *directory = this;
while (!uri.empty()) {
auto name = NextSegment(uri); for (std::string_view name : IterableSplitString(uri, '/')) {
if (name.empty())
continue;
auto i = directory->children.emplace(std::move(name), auto i = directory->children.emplace(std::move(name),
Directory()); Directory());
directory = &i.first->second; directory = &i.first->second;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment