From b2ed29b8c069c09999e151dc51673d609f2ed092 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 4 Jan 2024 13:21:53 +0100 Subject: [PATCH] lib/upnp/ContentDirectoryService: getFriendlyName() returns std::string reference This can avoid the overhead of casting a C string back to std::string_view. --- src/db/plugins/upnp/UpnpDatabasePlugin.cxx | 11 +++++------ src/lib/upnp/ContentDirectoryService.hxx | 4 ++-- src/neighbor/plugins/UpnpNeighborPlugin.cxx | 6 +++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/db/plugins/upnp/UpnpDatabasePlugin.cxx b/src/db/plugins/upnp/UpnpDatabasePlugin.cxx index 4b40544e5..c4abce24a 100644 --- a/src/db/plugins/upnp/UpnpDatabasePlugin.cxx +++ b/src/db/plugins/upnp/UpnpDatabasePlugin.cxx @@ -357,7 +357,7 @@ UpnpDatabase::SearchSongs(const ContentDirectoryService &server, // course, 'All Music' is very big. // So we return synthetic and ugly paths based on the object id, // which we later have to detect. - const std::string path = songPath(server.getFriendlyName(), + const std::string path = songPath(server.GetFriendlyName(), dirent.id); visitSong(dirent, path.c_str(), selection, visit_song); @@ -391,8 +391,7 @@ UpnpDatabase::BuildPath(const ContentDirectoryService &server, path = PathTraitsUTF8::Build(dirent.name, path); } - return PathTraitsUTF8::Build(server.getFriendlyName(), - path.c_str()); + return PathTraitsUTF8::Build(server.GetFriendlyName(), path); } // Take server and internal title pathname and return objid and metadata. @@ -519,7 +518,7 @@ UpnpDatabase::VisitServer(const ContentDirectoryService &server, throw DatabaseError(DatabaseErrorCode::NOT_FOUND, "Not found"); - std::string path = songPath(server.getFriendlyName(), + std::string path = songPath(server.GetFriendlyName(), dirent.id); visitSong(dirent, path.c_str(), selection, visit_song); @@ -541,7 +540,7 @@ UpnpDatabase::VisitServer(const ContentDirectoryService &server, } const char *const base_uri = selection.uri.empty() - ? server.getFriendlyName() + ? server.GetFriendlyName().c_str() : selection.uri.c_str(); if (tdirent.type == UPnPDirObject::Type::ITEM) { @@ -587,7 +586,7 @@ UpnpDatabase::Visit(const DatabaseSelection &selection, if (vpath.empty()) { for (const auto &server : discovery->GetDirectories()) { if (visit_directory) { - const LightDirectory d(server.getFriendlyName(), + const LightDirectory d(server.GetFriendlyName().c_str(), std::chrono::system_clock::time_point::min()); visit_directory(d); } diff --git a/src/lib/upnp/ContentDirectoryService.hxx b/src/lib/upnp/ContentDirectoryService.hxx index a4e26e4aa..10ce7af70 100644 --- a/src/lib/upnp/ContentDirectoryService.hxx +++ b/src/lib/upnp/ContentDirectoryService.hxx @@ -98,7 +98,7 @@ public: } /** Retrieve the "friendly name" for this server, useful for display. */ - const char *getFriendlyName() const noexcept { - return m_friendlyName.c_str(); + const std::string &GetFriendlyName() const noexcept { + return m_friendlyName; } }; diff --git a/src/neighbor/plugins/UpnpNeighborPlugin.cxx b/src/neighbor/plugins/UpnpNeighborPlugin.cxx index 6ea31b6de..d52df2213 100644 --- a/src/neighbor/plugins/UpnpNeighborPlugin.cxx +++ b/src/neighbor/plugins/UpnpNeighborPlugin.cxx @@ -91,21 +91,21 @@ UpnpNeighborExplorer::GetList() const noexcept List result; for (const auto &i : tmp) - result.emplace_front(i.GetURI(), i.getFriendlyName()); + result.emplace_front(i.GetURI(), i.GetFriendlyName()); return result; } void UpnpNeighborExplorer::FoundUPnP(const ContentDirectoryService &service) { - const NeighborInfo n(service.GetURI(), service.getFriendlyName()); + const NeighborInfo n(service.GetURI(), service.GetFriendlyName()); listener.FoundNeighbor(n); } void UpnpNeighborExplorer::LostUPnP(const ContentDirectoryService &service) { - const NeighborInfo n(service.GetURI(), service.getFriendlyName()); + const NeighborInfo n(service.GetURI(), service.GetFriendlyName()); listener.LostNeighbor(n); }