aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-10 20:51:16 +0100
committerMax Kellermann <max@duempel.org>2014-01-10 22:57:16 +0100
commite7eb04954d79955201316a91c72aabcfc724297f (patch)
tree58b3e0517e78222b8b8e0716f435fc8318c895e8
parent09b00fa4e318af53821318a502010eb10b5064de (diff)
downloadmpd-e7eb04954d79955201316a91c72aabcfc724297f.tar.gz
mpd-e7eb04954d79955201316a91c72aabcfc724297f.tar.xz
mpd-e7eb04954d79955201316a91c72aabcfc724297f.zip
db/upnp/Directory: don't use std::map to parse upnp:class
Reduce excessive bloat.
-rw-r--r--src/db/upnp/Directory.cxx27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/db/upnp/Directory.cxx b/src/db/upnp/Directory.cxx
index da55f08e5..1ae72b107 100644
--- a/src/db/upnp/Directory.cxx
+++ b/src/db/upnp/Directory.cxx
@@ -37,6 +37,18 @@ static const char *const upnptags[] = {
};
static const int nupnptags = sizeof(upnptags) / sizeof(char*);
+gcc_pure
+static UPnPDirObject::ItemClass
+ParseItemClass(const char *name)
+{
+ if (strcmp(name, "object.item.audioItem.musicTrack") == 0)
+ return UPnPDirObject::ItemClass::MUSIC;
+ else if (strcmp(name, "object.item.playlistItem") == 0)
+ return UPnPDirObject::ItemClass::PLAYLIST;
+ else
+ return UPnPDirObject::ItemClass::UNKNOWN;
+}
+
/**
* An XML parser which builds directory contents from DIDL lite input.
*/
@@ -49,16 +61,11 @@ class UPnPDirParser final : public CommonExpatParser {
std::vector<StackEl> m_path;
UPnPDirObject m_tobj;
- std::map<std::string, UPnPDirObject::ItemClass> m_okitems;
public:
UPnPDirParser(UPnPDirContent& dir)
:m_dir(dir)
{
- m_okitems["object.item.audioItem.musicTrack"] =
- UPnPDirObject::ItemClass::MUSIC;
- m_okitems["object.item.playlistItem"] =
- UPnPDirObject::ItemClass::PLAYLIST;
}
UPnPDirContent& m_dir;
@@ -97,13 +104,15 @@ protected:
!m_tobj.m_title.empty();
if (ok && m_tobj.type == UPnPDirObject::Type::ITEM) {
- auto it = m_okitems.find(m_tobj.m_props["upnp:class"]);
- if (it == m_okitems.end()) {
+ const char *item_class_name =
+ m_tobj.m_props["upnp:class"].c_str();
+ auto item_class = ParseItemClass(item_class_name);
+ if (item_class == UPnPDirObject::ItemClass::UNKNOWN) {
PLOGINF("checkobjok: found object of unknown class: [%s]\n",
- m_tobj.m_props["upnp:class"].c_str());
+ item_class_name);
ok = false;
} else {
- m_tobj.item_class = it->second;
+ m_tobj.item_class = item_class;
}
}