db/upnp: move Tag from UPnPDirObject to Song

The UPnPDirObject is a temporary object, we can move its contents.
This reduces runtime overhead.
This commit is contained in:
Max Kellermann 2014-01-18 19:09:42 +01:00
parent fab6cbed75
commit fdf4dff561
1 changed files with 14 additions and 11 deletions

View File

@ -199,13 +199,13 @@ UpnpDatabase::ReturnSong(Song *song) const
// "add"ing AFAIK. Visit() calls us with a null uri so that the url // "add"ing AFAIK. Visit() calls us with a null uri so that the url
// appropriate for fetching is used instead. // appropriate for fetching is used instead.
static Song * static Song *
upnpItemToSong(const UPnPDirObject &dirent, const char *uri) upnpItemToSong(UPnPDirObject &&dirent, const char *uri)
{ {
if (*uri == 0) if (*uri == 0)
uri = dirent.url.c_str(); uri = dirent.url.c_str();
Song *s = Song::NewFile(uri, nullptr); Song *s = Song::NewFile(uri, nullptr);
s->tag = new Tag(dirent.tag); s->tag = new Tag(std::move(dirent.tag));
return s; return s;
} }
@ -232,7 +232,7 @@ UpnpDatabase::GetSong(const char *uri, Error &error) const
error)) error))
return nullptr; return nullptr;
} }
song = upnpItemToSong(dirent, ""); song = upnpItemToSong(std::move(dirent), "");
} }
if (song == nullptr) if (song == nullptr)
error.Format(db_domain, DB_NOT_FOUND, "No such song: %s", uri); error.Format(db_domain, DB_NOT_FOUND, "No such song: %s", uri);
@ -351,13 +351,13 @@ UpnpDatabase::SearchSongs(ContentDirectoryService &server,
} }
static bool static bool
visitSong(const UPnPDirObject& meta, const char *path, visitSong(UPnPDirObject &&meta, const char *path,
const DatabaseSelection &selection, const DatabaseSelection &selection,
VisitSong visit_song, Error& error) VisitSong visit_song, Error& error)
{ {
if (!visit_song) if (!visit_song)
return true; return true;
Song *s = upnpItemToSong(meta, path); Song *s = upnpItemToSong(std::move(meta), path);
if (!selection.Match(*s)) if (!selection.Match(*s))
return true; return true;
bool success = visit_song(*s, error); bool success = visit_song(*s, error);
@ -390,7 +390,7 @@ UpnpDatabase::SearchSongs(ContentDirectoryService &server,
if (!SearchSongs(server, objid, selection, dirbuf, error)) if (!SearchSongs(server, objid, selection, dirbuf, error))
return false; return false;
for (const auto &dirent : dirbuf.objects) { for (auto &dirent : dirbuf.objects) {
if (dirent.type != UPnPDirObject::Type::ITEM || if (dirent.type != UPnPDirObject::Type::ITEM ||
dirent.item_class != UPnPDirObject::ItemClass::MUSIC) dirent.item_class != UPnPDirObject::ItemClass::MUSIC)
continue; continue;
@ -414,7 +414,8 @@ UpnpDatabase::SearchSongs(ContentDirectoryService &server,
std::string path = songPath(server.getFriendlyName(), std::string path = songPath(server.getFriendlyName(),
dirent.m_id); dirent.m_id);
//BuildPath(server, dirent, path); //BuildPath(server, dirent, path);
if (!visitSong(dirent, path.c_str(), selection, visit_song, if (!visitSong(std::move(dirent), path.c_str(),
selection, visit_song,
error)) error))
return false; return false;
} }
@ -553,7 +554,7 @@ UpnpDatabase::VisitServer(ContentDirectoryService &server,
error)) error))
return false; return false;
if (!visitSong(dirent, "", selection, if (!visitSong(std::move(dirent), "", selection,
visit_song, error)) visit_song, error))
return false; return false;
} }
@ -584,7 +585,8 @@ UpnpDatabase::VisitServer(ContentDirectoryService &server,
switch (tdirent.item_class) { switch (tdirent.item_class) {
case UPnPDirObject::ItemClass::MUSIC: case UPnPDirObject::ItemClass::MUSIC:
if (visit_song) if (visit_song)
return visitSong(tdirent, "", selection, visit_song, return visitSong(std::move(tdirent), "",
selection, visit_song,
error); error);
break; break;
@ -611,7 +613,7 @@ UpnpDatabase::VisitServer(ContentDirectoryService &server,
if (!server.readDir(m_lib->getclh(), objid.c_str(), dirbuf, error)) if (!server.readDir(m_lib->getclh(), objid.c_str(), dirbuf, error))
return false; return false;
for (const auto &dirent : dirbuf.objects) { for (auto &dirent : dirbuf.objects) {
switch (dirent.type) { switch (dirent.type) {
case UPnPDirObject::Type::UNKNOWN: case UPnPDirObject::Type::UNKNOWN:
assert(false); assert(false);
@ -642,7 +644,8 @@ UpnpDatabase::VisitServer(ContentDirectoryService &server,
p = selection.uri + "/" + p = selection.uri + "/" +
dirent.name; dirent.name;
if (!visitSong(dirent, p.c_str(), if (!visitSong(std::move(dirent),
p.c_str(),
selection, visit_song, error)) selection, visit_song, error))
return false; return false;
} }