From f2a4ae15aa855671f315546ef410fc700cb6da46 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 30 Apr 2023 08:23:11 +0200 Subject: [PATCH] db/update: pass filenames as std::string_view --- src/db/update/Archive.cxx | 13 ++++++------- src/db/update/UpdateSong.cxx | 4 ++-- src/db/update/Walk.hxx | 8 ++++---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/db/update/Archive.cxx b/src/db/update/Archive.cxx index 93171fd95..db78904fe 100644 --- a/src/db/update/Archive.cxx +++ b/src/db/update/Archive.cxx @@ -14,7 +14,7 @@ #include "archive/ArchivePlugin.hxx" #include "archive/ArchiveFile.hxx" #include "archive/ArchiveVisitor.hxx" -#include "util/StringCompare.hxx" +#include "util/StringSplit.hxx" #include "Log.hxx" #include @@ -37,19 +37,18 @@ LockFindSong(Directory &directory, std::string_view name) noexcept void UpdateWalk::UpdateArchiveTree(ArchiveFile &archive, Directory &directory, - const char *name) noexcept + std::string_view name) noexcept { - const char *tmp = std::strchr(name, '/'); - if (tmp) { - const std::string_view child_name(name, tmp - name); + const auto [child_name, rest] = Split(name, '/'); + if (rest.data() != nullptr) { //add dir is not there already Directory *subdir = LockMakeChild(directory, child_name); subdir->device = DEVICE_INARCHIVE; //create directories first - UpdateArchiveTree(archive, *subdir, tmp + 1); + UpdateArchiveTree(archive, *subdir, rest); } else { - if (StringIsEmpty(name)) { + if (name.empty()) { LogWarning(update_domain, "archive returned directory only"); return; diff --git a/src/db/update/UpdateSong.cxx b/src/db/update/UpdateSong.cxx index 5bf476e8a..fdf8de56c 100644 --- a/src/db/update/UpdateSong.cxx +++ b/src/db/update/UpdateSong.cxx @@ -16,7 +16,7 @@ inline void UpdateWalk::UpdateSongFile2(Directory &directory, - const char *name, std::string_view suffix, + std::string_view name, std::string_view suffix, const StorageFileInfo &info) noexcept try { Song *song; @@ -83,7 +83,7 @@ try { bool UpdateWalk::UpdateSongFile(Directory &directory, - const char *name, std::string_view suffix, + std::string_view name, std::string_view suffix, const StorageFileInfo &info) noexcept { if (!decoder_plugins_supports_suffix(suffix)) diff --git a/src/db/update/Walk.hxx b/src/db/update/Walk.hxx index d1817da9e..4e6ac27be 100644 --- a/src/db/update/Walk.hxx +++ b/src/db/update/Walk.hxx @@ -79,11 +79,11 @@ private: void PurgeDanglingFromPlaylists(Directory &directory) noexcept; void UpdateSongFile2(Directory &directory, - const char *name, std::string_view suffix, + std::string_view name, std::string_view suffix, const StorageFileInfo &info) noexcept; bool UpdateSongFile(Directory &directory, - const char *name, std::string_view suffix, + std::string_view name, std::string_view suffix, const StorageFileInfo &info) noexcept; bool UpdateContainerFile(Directory &directory, @@ -93,7 +93,7 @@ private: #ifdef ENABLE_ARCHIVE void UpdateArchiveTree(ArchiveFile &archive, Directory &parent, - const char *name) noexcept; + std::string_view name) noexcept; bool UpdateArchiveFile(Directory &directory, std::string_view name, std::string_view suffix, @@ -106,7 +106,7 @@ private: #else bool UpdateArchiveFile([[maybe_unused]] Directory &directory, - [[maybe_unused]] const char *name, + [[maybe_unused]] std::string_view name, [[maybe_unused]] std::string_view suffix, [[maybe_unused]] const StorageFileInfo &info) noexcept { return false;