From e2d2bb8755a617d3dc0de15d2dc3f33829290428 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 3 Apr 2020 19:49:19 +0200 Subject: [PATCH] storage/Composite: use IterableSplitString() --- src/storage/CompositeStorage.cxx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/storage/CompositeStorage.cxx b/src/storage/CompositeStorage.cxx index 2833cab25..ba6858415 100644 --- a/src/storage/CompositeStorage.cxx +++ b/src/storage/CompositeStorage.cxx @@ -20,6 +20,7 @@ #include "CompositeStorage.hxx" #include "FileInfo.hxx" #include "fs/AllocatedPath.hxx" +#include "util/IterableSplitString.hxx" #include "util/StringCompare.hxx" #include @@ -95,8 +96,11 @@ const CompositeStorage::Directory * CompositeStorage::Directory::Find(std::string_view uri) const noexcept { 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); if (i == directory->children.end()) return nullptr; @@ -111,8 +115,11 @@ CompositeStorage::Directory & CompositeStorage::Directory::Make(std::string_view uri) { 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), Directory()); directory = &i.first->second;