aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-23 22:18:40 +0100
committerMax Kellermann <max@duempel.org>2014-01-23 22:35:22 +0100
commitb8e382b011e524ed4577fbc5b0871f86f1c196d4 (patch)
treed72bd389c91668dd0f315c0152b5d6abb30fe841
parentc9af358e4bbc39da7dfe3ce650008c12ac3f8335 (diff)
downloadmpd-b8e382b011e524ed4577fbc5b0871f86f1c196d4.tar.gz
mpd-b8e382b011e524ed4577fbc5b0871f86f1c196d4.tar.xz
mpd-b8e382b011e524ed4577fbc5b0871f86f1c196d4.zip
db/upnp/Discovery: use std::list instead of std::map
There will only be very few items, and that does not justify the bloat of std::map.
-rw-r--r--src/db/upnp/Discovery.cxx36
-rw-r--r--src/db/upnp/Discovery.hxx13
2 files changed, 33 insertions, 16 deletions
diff --git a/src/db/upnp/Discovery.cxx b/src/db/upnp/Discovery.cxx
index 4aeb381fd..5203dba83 100644
--- a/src/db/upnp/Discovery.cxx
+++ b/src/db/upnp/Discovery.cxx
@@ -54,19 +54,32 @@ isMSDevice(const char *st)
}
inline void
-UPnPDeviceDirectory::LockAdd(std::string &&id, ContentDirectoryDescriptor &&d)
+UPnPDeviceDirectory::LockAdd(ContentDirectoryDescriptor &&d)
{
const ScopeLock protect(mutex);
- directories[std::move(id)] = std::move(d);
+
+ for (auto &i : directories) {
+ if (i.id == d.id) {
+ i = std::move(d);
+ return;
+ }
+ }
+
+ directories.emplace_back(std::move(d));
}
inline void
UPnPDeviceDirectory::LockRemove(const std::string &id)
{
const ScopeLock protect(mutex);
- auto i = directories.find(id);
- if (i != directories.end())
- directories.erase(i);
+
+ for (auto i = directories.begin(), end = directories.end();
+ i != end; ++i) {
+ if (i->id == id) {
+ directories.erase(i);
+ break;
+ }
+ }
}
inline void
@@ -91,7 +104,8 @@ UPnPDeviceDirectory::discoExplorer()
}
// Update or insert the device
- ContentDirectoryDescriptor d(MonotonicClockS(), tsk->expires);
+ ContentDirectoryDescriptor d(std::move(tsk->deviceId),
+ MonotonicClockS(), tsk->expires);
{
Error error2;
@@ -104,7 +118,7 @@ UPnPDeviceDirectory::discoExplorer()
}
}
- LockAdd(std::move(tsk->deviceId), std::move(d));
+ LockAdd(std::move(d));
delete tsk;
}
}
@@ -180,7 +194,7 @@ UPnPDeviceDirectory::expireDevices(Error &error)
for (auto it = directories.begin();
it != directories.end();) {
- if (now > it->second.expires) {
+ if (now > it->expires) {
it = directories.erase(it);
didsomething = true;
} else {
@@ -263,9 +277,9 @@ UPnPDeviceDirectory::getDirServices(std::vector<ContentDirectoryService> &out,
for (auto dit = directories.begin();
dit != directories.end(); dit++) {
- for (const auto &service : dit->second.device.services) {
+ for (const auto &service : dit->device.services) {
if (isCDService(service.serviceType.c_str())) {
- out.emplace_back(dit->second.device, service);
+ out.emplace_back(dit->device, service);
}
}
}
@@ -285,7 +299,7 @@ UPnPDeviceDirectory::getServer(const char *friendlyName,
const ScopeLock protect(mutex);
for (const auto &i : directories) {
- const auto &device = i.second.device;
+ const auto &device = i.device;
if (device.friendlyName != friendlyName)
continue;
diff --git a/src/db/upnp/Discovery.hxx b/src/db/upnp/Discovery.hxx
index fec9fe1fb..4c64fe420 100644
--- a/src/db/upnp/Discovery.hxx
+++ b/src/db/upnp/Discovery.hxx
@@ -27,7 +27,7 @@
#include <upnp/upnp.h>
-#include <map>
+#include <list>
#include <vector>
#include <string>
@@ -63,6 +63,8 @@ class UPnPDeviceDirectory {
*/
class ContentDirectoryDescriptor {
public:
+ std::string id;
+
UPnPDevice device;
/**
@@ -73,8 +75,9 @@ class UPnPDeviceDirectory {
ContentDirectoryDescriptor() = default;
- ContentDirectoryDescriptor(unsigned last, int exp)
- :expires(last + exp + 20) {}
+ ContentDirectoryDescriptor(std::string &&_id,
+ unsigned last, int exp)
+ :id(std::move(_id)), expires(last + exp + 20) {}
bool Parse(const std::string &url, const char *description,
Error &_error) {
@@ -85,7 +88,7 @@ class UPnPDeviceDirectory {
LibUPnP *const lib;
Mutex mutex;
- std::map<std::string, ContentDirectoryDescriptor> directories;
+ std::list<ContentDirectoryDescriptor> directories;
WorkQueue<DiscoveredTask *> discoveredQueue;
/**
@@ -129,7 +132,7 @@ private:
*/
bool expireDevices(Error &error);
- void LockAdd(std::string &&id, ContentDirectoryDescriptor &&d);
+ void LockAdd(ContentDirectoryDescriptor &&d);
void LockRemove(const std::string &id);
/**