aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-18 16:18:51 +0100
committerMax Kellermann <max@duempel.org>2014-01-18 16:18:51 +0100
commit0696cac50bfc9430e5094112dc5019be70998012 (patch)
tree28e14651b80108bb895faa9e5cf3d4f0e703a0ce
parent0c2485e86c280c69752a8fa6101e8d77ee4b9b25 (diff)
downloadmpd-0696cac50bfc9430e5094112dc5019be70998012.tar.gz
mpd-0696cac50bfc9430e5094112dc5019be70998012.tar.xz
mpd-0696cac50bfc9430e5094112dc5019be70998012.zip
db/upnp/Discovery: eliminate full copy in getServer()
Diffstat (limited to '')
-rw-r--r--src/db/upnp/Discovery.cxx22
-rw-r--r--src/db/upnp/Discovery.hxx4
2 files changed, 17 insertions, 9 deletions
diff --git a/src/db/upnp/Discovery.cxx b/src/db/upnp/Discovery.cxx
index f47741240..371f87244 100644
--- a/src/db/upnp/Discovery.cxx
+++ b/src/db/upnp/Discovery.cxx
@@ -262,14 +262,24 @@ UPnPDeviceDirectory::getServer(const char *friendlyName,
ContentDirectoryService &server,
Error &error)
{
- std::vector<ContentDirectoryService> ds;
- if (!getDirServices(ds, error))
+ // Has locking, do it before our own lock
+ if (!expireDevices(error))
return false;
- for (const auto &i : ds) {
- if (strcmp(friendlyName, i.getFriendlyName()) == 0) {
- server = i;
- return true;
+ const ScopeLock protect(mutex);
+
+ for (const auto &i : directories) {
+ const auto &device = i.second.device;
+
+ if (device.friendlyName != friendlyName)
+ continue;
+
+ for (const auto &service : device.services) {
+ if (isCDService(service.serviceType.c_str())) {
+ server = ContentDirectoryService(device,
+ service);
+ return true;
+ }
}
}
diff --git a/src/db/upnp/Discovery.hxx b/src/db/upnp/Discovery.hxx
index 59eed9331..d1df9f666 100644
--- a/src/db/upnp/Discovery.hxx
+++ b/src/db/upnp/Discovery.hxx
@@ -107,9 +107,7 @@ public:
bool getDirServices(std::vector<ContentDirectoryService> &, Error &);
/**
- * Get server by friendly name. It's a bit wasteful to copy
- * all servers for this, we could directly walk the list. Otoh
- * there isn't going to be millions...
+ * Get server by friendly name.
*/
bool getServer(const char *friendlyName,
ContentDirectoryService &server,