From ddc75cc46b35639bfbb8fe014070d8948a259dad Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 14 Jan 2014 12:36:15 +0100 Subject: db/upnp/Directory: merge m_containers and m_items There is no use in duplicating these containers. It only means that we have to search both, duplicating the code. --- src/db/upnp/Directory.cxx | 12 +++--------- src/db/upnp/Directory.hxx | 13 +++++++++++-- 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'src/db/upnp') diff --git a/src/db/upnp/Directory.cxx b/src/db/upnp/Directory.cxx index cc28ec295..8a6708a67 100644 --- a/src/db/upnp/Directory.cxx +++ b/src/db/upnp/Directory.cxx @@ -149,15 +149,9 @@ protected: virtual void EndElement(const XML_Char *name) { - if (!strcmp(name, "container")) { - if (checkobjok()) { - m_dir.m_containers.push_back(m_tobj); - } - } else if (!strcmp(name, "item")) { - if (checkobjok()) { - m_dir.m_items.push_back(m_tobj); - } - } + if ((!strcmp(name, "container") || !strcmp(name, "item")) && + checkobjok()) + m_dir.objects.push_back(m_tobj); m_path.pop_back(); } diff --git a/src/db/upnp/Directory.hxx b/src/db/upnp/Directory.hxx index 55dc09c71..3324b2232 100644 --- a/src/db/upnp/Directory.hxx +++ b/src/db/upnp/Directory.hxx @@ -21,6 +21,7 @@ #define MPD_UPNP_DIRECTORY_HXX #include "Object.hxx" +#include "Compiler.h" #include #include @@ -33,8 +34,16 @@ class Error; */ class UPnPDirContent { public: - std::vector m_containers; - std::vector m_items; + std::vector objects; + + gcc_pure + const UPnPDirObject *FindObject(const char *name) const { + for (const auto &o : objects) + if (o.name == name) + return &o; + + return nullptr; + } /** * Parse from DIDL-Lite XML data. -- cgit v1.2.3