aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-10 21:27:36 +0100
committerMax Kellermann <max@duempel.org>2014-01-10 22:59:01 +0100
commitf4490f6918a1b481c535b1b63179edb78382e02e (patch)
tree35f0a5f7eb08902922af1b9b9fb5b4d7b7f957af /src
parentdadd987bf441324bf8824c16f3ac0798da652083 (diff)
downloadmpd-f4490f6918a1b481c535b1b63179edb78382e02e.tar.gz
mpd-f4490f6918a1b481c535b1b63179edb78382e02e.tar.xz
mpd-f4490f6918a1b481c535b1b63179edb78382e02e.zip
db/upnp/Directory: eliminate the "attributes" std::map
Look up attributes in the "atts" array. Reduce bloat.
Diffstat (limited to 'src')
-rw-r--r--src/Expat.cxx11
-rw-r--r--src/Expat.hxx10
-rw-r--r--src/db/upnp/Directory.cxx30
3 files changed, 40 insertions, 11 deletions
diff --git a/src/Expat.cxx b/src/Expat.cxx
index 82dce7682..5cee45912 100644
--- a/src/Expat.cxx
+++ b/src/Expat.cxx
@@ -70,6 +70,17 @@ ExpatParser::Parse(InputStream &is, Error &error)
}
const char *
+ExpatParser::GetAttribute(const XML_Char **atts,
+ const char *name)
+{
+ for (unsigned i = 0; atts[i] != nullptr; i += 2)
+ if (strcmp(atts[i], name) == 0)
+ return atts[i + 1];
+
+ return nullptr;
+}
+
+const char *
ExpatParser::GetAttributeCase(const XML_Char **atts,
const char *name)
{
diff --git a/src/Expat.hxx b/src/Expat.hxx
index 9fcdf61d4..d57a85533 100644
--- a/src/Expat.hxx
+++ b/src/Expat.hxx
@@ -56,6 +56,10 @@ public:
bool Parse(InputStream &is, Error &error);
gcc_pure
+ static const char *GetAttribute(const XML_Char **atts,
+ const char *name);
+
+ gcc_pure
static const char *GetAttributeCase(const XML_Char **atts,
const char *name);
@@ -86,6 +90,12 @@ public:
}
gcc_pure
+ static const char *GetAttribute(const XML_Char **atts,
+ const char *name) {
+ return ExpatParser::GetAttribute(atts, name);
+ }
+
+ gcc_pure
static const char *GetAttributeCase(const XML_Char **atts,
const char *name) {
return ExpatParser::GetAttributeCase(atts, name);
diff --git a/src/db/upnp/Directory.cxx b/src/db/upnp/Directory.cxx
index ed08eb022..fb57cdad7 100644
--- a/src/db/upnp/Directory.cxx
+++ b/src/db/upnp/Directory.cxx
@@ -24,7 +24,6 @@
#include <string>
#include <vector>
-#include <map>
#include <string.h>
@@ -78,17 +77,19 @@ protected:
{
m_path.push_back(name);
- std::map<std::string,std::string> attributes;
- for (int i = 0; attrs[i] != 0; i += 2)
- attributes[attrs[i]] = attrs[i+1];
-
switch (name[0]) {
case 'c':
if (!strcmp(name, "container")) {
m_tobj.clear();
m_tobj.type = UPnPDirObject::Type::CONTAINER;
- m_tobj.m_id = attributes["id"];
- m_tobj.m_pid = attributes["parentID"];
+
+ const char *id = GetAttribute(attrs, "id");
+ if (id != nullptr)
+ m_tobj.m_id = id;
+
+ const char *pid = GetAttribute(attrs, "parentID");
+ if (pid != nullptr)
+ m_tobj.m_pid = pid;
}
break;
@@ -96,8 +97,14 @@ protected:
if (!strcmp(name, "item")) {
m_tobj.clear();
m_tobj.type = UPnPDirObject::Type::ITEM;
- m_tobj.m_id = attributes["id"];
- m_tobj.m_pid = attributes["parentID"];
+
+ const char *id = GetAttribute(attrs, "id");
+ if (id != nullptr)
+ m_tobj.m_id = id;
+
+ const char *pid = GetAttribute(attrs, "parentID");
+ if (pid != nullptr)
+ m_tobj.m_pid = pid;
}
break;
@@ -108,8 +115,9 @@ protected:
// nrAudioChannels="2">
for (auto i = res_attributes; *i != nullptr; ++i) {
- const std::string s(*i);
- m_tobj.m_props[s] = attributes[s];
+ const char *value = GetAttribute(attrs, *i);
+ if (value != nullptr)
+ m_tobj.m_props.emplace(*i, value);
}
}