lib/upnp/ContentDirectoryService: getFriendlyName() returns std::string reference

This can avoid the overhead of casting a C string back to std::string_view.
This commit is contained in:
Max Kellermann 2024-01-04 13:21:53 +01:00
parent 1789b56a85
commit b2ed29b8c0
3 changed files with 10 additions and 11 deletions

View File

@ -357,7 +357,7 @@ UpnpDatabase::SearchSongs(const ContentDirectoryService &server,
// course, 'All Music' is very big. // course, 'All Music' is very big.
// So we return synthetic and ugly paths based on the object id, // So we return synthetic and ugly paths based on the object id,
// which we later have to detect. // which we later have to detect.
const std::string path = songPath(server.getFriendlyName(), const std::string path = songPath(server.GetFriendlyName(),
dirent.id); dirent.id);
visitSong(dirent, path.c_str(), visitSong(dirent, path.c_str(),
selection, visit_song); selection, visit_song);
@ -391,8 +391,7 @@ UpnpDatabase::BuildPath(const ContentDirectoryService &server,
path = PathTraitsUTF8::Build(dirent.name, path); path = PathTraitsUTF8::Build(dirent.name, path);
} }
return PathTraitsUTF8::Build(server.getFriendlyName(), return PathTraitsUTF8::Build(server.GetFriendlyName(), path);
path.c_str());
} }
// Take server and internal title pathname and return objid and metadata. // 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, throw DatabaseError(DatabaseErrorCode::NOT_FOUND,
"Not found"); "Not found");
std::string path = songPath(server.getFriendlyName(), std::string path = songPath(server.GetFriendlyName(),
dirent.id); dirent.id);
visitSong(dirent, path.c_str(), visitSong(dirent, path.c_str(),
selection, visit_song); selection, visit_song);
@ -541,7 +540,7 @@ UpnpDatabase::VisitServer(const ContentDirectoryService &server,
} }
const char *const base_uri = selection.uri.empty() const char *const base_uri = selection.uri.empty()
? server.getFriendlyName() ? server.GetFriendlyName().c_str()
: selection.uri.c_str(); : selection.uri.c_str();
if (tdirent.type == UPnPDirObject::Type::ITEM) { if (tdirent.type == UPnPDirObject::Type::ITEM) {
@ -587,7 +586,7 @@ UpnpDatabase::Visit(const DatabaseSelection &selection,
if (vpath.empty()) { if (vpath.empty()) {
for (const auto &server : discovery->GetDirectories()) { for (const auto &server : discovery->GetDirectories()) {
if (visit_directory) { if (visit_directory) {
const LightDirectory d(server.getFriendlyName(), const LightDirectory d(server.GetFriendlyName().c_str(),
std::chrono::system_clock::time_point::min()); std::chrono::system_clock::time_point::min());
visit_directory(d); visit_directory(d);
} }

View File

@ -98,7 +98,7 @@ public:
} }
/** Retrieve the "friendly name" for this server, useful for display. */ /** Retrieve the "friendly name" for this server, useful for display. */
const char *getFriendlyName() const noexcept { const std::string &GetFriendlyName() const noexcept {
return m_friendlyName.c_str(); return m_friendlyName;
} }
}; };

View File

@ -91,21 +91,21 @@ UpnpNeighborExplorer::GetList() const noexcept
List result; List result;
for (const auto &i : tmp) for (const auto &i : tmp)
result.emplace_front(i.GetURI(), i.getFriendlyName()); result.emplace_front(i.GetURI(), i.GetFriendlyName());
return result; return result;
} }
void void
UpnpNeighborExplorer::FoundUPnP(const ContentDirectoryService &service) UpnpNeighborExplorer::FoundUPnP(const ContentDirectoryService &service)
{ {
const NeighborInfo n(service.GetURI(), service.getFriendlyName()); const NeighborInfo n(service.GetURI(), service.GetFriendlyName());
listener.FoundNeighbor(n); listener.FoundNeighbor(n);
} }
void void
UpnpNeighborExplorer::LostUPnP(const ContentDirectoryService &service) UpnpNeighborExplorer::LostUPnP(const ContentDirectoryService &service)
{ {
const NeighborInfo n(service.GetURI(), service.getFriendlyName()); const NeighborInfo n(service.GetURI(), service.GetFriendlyName());
listener.LostNeighbor(n); listener.LostNeighbor(n);
} }