db/upnp/Directory: eliminate the "attributes" std::map
Look up attributes in the "atts" array. Reduce bloat.
This commit is contained in:
parent
dadd987bf4
commit
f4490f6918
@ -69,6 +69,17 @@ ExpatParser::Parse(InputStream &is, Error &error)
|
|||||||
return Parse("", 0, true, error);
|
return Parse("", 0, true, 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 *
|
const char *
|
||||||
ExpatParser::GetAttributeCase(const XML_Char **atts,
|
ExpatParser::GetAttributeCase(const XML_Char **atts,
|
||||||
const char *name)
|
const char *name)
|
||||||
|
@ -55,6 +55,10 @@ public:
|
|||||||
|
|
||||||
bool Parse(InputStream &is, Error &error);
|
bool Parse(InputStream &is, Error &error);
|
||||||
|
|
||||||
|
gcc_pure
|
||||||
|
static const char *GetAttribute(const XML_Char **atts,
|
||||||
|
const char *name);
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
static const char *GetAttributeCase(const XML_Char **atts,
|
static const char *GetAttributeCase(const XML_Char **atts,
|
||||||
const char *name);
|
const char *name);
|
||||||
@ -85,6 +89,12 @@ public:
|
|||||||
return parser.Parse(is, error);
|
return parser.Parse(is, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gcc_pure
|
||||||
|
static const char *GetAttribute(const XML_Char **atts,
|
||||||
|
const char *name) {
|
||||||
|
return ExpatParser::GetAttribute(atts, name);
|
||||||
|
}
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
static const char *GetAttributeCase(const XML_Char **atts,
|
static const char *GetAttributeCase(const XML_Char **atts,
|
||||||
const char *name) {
|
const char *name) {
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -78,17 +77,19 @@ protected:
|
|||||||
{
|
{
|
||||||
m_path.push_back(name);
|
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]) {
|
switch (name[0]) {
|
||||||
case 'c':
|
case 'c':
|
||||||
if (!strcmp(name, "container")) {
|
if (!strcmp(name, "container")) {
|
||||||
m_tobj.clear();
|
m_tobj.clear();
|
||||||
m_tobj.type = UPnPDirObject::Type::CONTAINER;
|
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;
|
break;
|
||||||
|
|
||||||
@ -96,8 +97,14 @@ protected:
|
|||||||
if (!strcmp(name, "item")) {
|
if (!strcmp(name, "item")) {
|
||||||
m_tobj.clear();
|
m_tobj.clear();
|
||||||
m_tobj.type = UPnPDirObject::Type::ITEM;
|
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;
|
break;
|
||||||
|
|
||||||
@ -108,8 +115,9 @@ protected:
|
|||||||
// nrAudioChannels="2">
|
// nrAudioChannels="2">
|
||||||
|
|
||||||
for (auto i = res_attributes; *i != nullptr; ++i) {
|
for (auto i = res_attributes; *i != nullptr; ++i) {
|
||||||
const std::string s(*i);
|
const char *value = GetAttribute(attrs, *i);
|
||||||
m_tobj.m_props[s] = attributes[s];
|
if (value != nullptr)
|
||||||
|
m_tobj.m_props.emplace(*i, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user