From 3a83a6b5274a7abb12c5d11392d872024a490e37 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 3 Apr 2020 19:25:46 +0200 Subject: [PATCH] storage/Composite: NextSegment() returns std::string_view --- src/storage/CompositeStorage.cxx | 12 ++++++------ src/storage/CompositeStorage.hxx | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/storage/CompositeStorage.cxx b/src/storage/CompositeStorage.cxx index 5bd5318e3..c124d0d31 100644 --- a/src/storage/CompositeStorage.cxx +++ b/src/storage/CompositeStorage.cxx @@ -82,17 +82,17 @@ CompositeDirectoryReader::GetInfo(bool follow) return StorageFileInfo(StorageFileInfo::Type::DIRECTORY); } -static std::string +static std::string_view NextSegment(const char *&uri_r) { const char *uri = uri_r; const char *slash = strchr(uri, '/'); if (slash == nullptr) { uri_r += strlen(uri); - return std::string(uri); + return uri; } else { uri_r = slash + 1; - return std::string(uri, slash); + return std::string_view(uri, slash - uri); } } @@ -101,7 +101,7 @@ CompositeStorage::Directory::Find(const char *uri) const noexcept { const Directory *directory = this; while (*uri != 0) { - const std::string name = NextSegment(uri); + const auto name = NextSegment(uri); auto i = directory->children.find(name); if (i == directory->children.end()) return nullptr; @@ -142,7 +142,7 @@ CompositeStorage::Directory::Unmount(const char *uri) noexcept if (StringIsEmpty(uri)) return Unmount(); - const std::string name = NextSegment(uri); + const auto name = NextSegment(uri); auto i = children.find(name); if (i == children.end() || !i->second.Unmount(uri)) @@ -227,7 +227,7 @@ CompositeStorage::FindStorage(const char *uri) const noexcept const Directory *directory = &root; while (*uri != 0) { - const std::string name = NextSegment(uri); + const auto name = NextSegment(uri); auto i = directory->children.find(name); if (i == directory->children.end()) diff --git a/src/storage/CompositeStorage.hxx b/src/storage/CompositeStorage.hxx index be6fdb66b..2646101a7 100644 --- a/src/storage/CompositeStorage.hxx +++ b/src/storage/CompositeStorage.hxx @@ -49,7 +49,7 @@ class CompositeStorage final : public Storage { */ std::unique_ptr storage; - std::map children; + std::map> children; gcc_pure bool IsEmpty() const noexcept {