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.
// 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);
}

View File

@ -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;
}
};

View File

@ -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);
}