From 46debfb8b54f19411376d2b486f51b48aa9b8cf9 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 14 Jan 2014 14:11:07 +0100 Subject: [PATCH] db/upnp/Object: disallow copying, always move Reduce bloat. --- src/db/UpnpDatabasePlugin.cxx | 9 ++++----- src/db/upnp/Directory.cxx | 2 +- src/db/upnp/Directory.hxx | 4 ++-- src/db/upnp/Object.hxx | 4 ++++ 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/db/UpnpDatabasePlugin.cxx b/src/db/UpnpDatabasePlugin.cxx index 436b22a80..92d520bba 100644 --- a/src/db/UpnpDatabasePlugin.cxx +++ b/src/db/UpnpDatabasePlugin.cxx @@ -488,7 +488,7 @@ UpnpDatabase::ReadNode(ContentDirectoryService *server, return false; if (dirbuf.objects.size() == 1) { - dirent = dirbuf.objects[0]; + dirent = std::move(dirbuf.objects[0]); } else { error.Format(upnp_domain, "Bad resource"); return false; @@ -542,8 +542,7 @@ UpnpDatabase::Namei(ContentDirectoryService* server, return false; // Look for the name in the sub-container list - const UPnPDirObject *child = - dirbuf.FindObject(vpath[i].c_str()); + UPnPDirObject *child = dirbuf.FindObject(vpath[i].c_str()); if (child == nullptr) break; @@ -558,7 +557,7 @@ UpnpDatabase::Namei(ContentDirectoryService* server, // The last element in the path was found and it's // a container, we're done oobjid = objid; - odirent = *child; + odirent = std::move(*child); return true; } break; @@ -568,7 +567,7 @@ UpnpDatabase::Namei(ContentDirectoryService* server, // else it does not exist if (i == vpath.size() - 1) { oobjid = objid; - odirent = *child; + odirent = std::move(*child); return true; } else { error.Format(db_domain, DB_NOT_FOUND, diff --git a/src/db/upnp/Directory.cxx b/src/db/upnp/Directory.cxx index 8a6708a67..35d556c28 100644 --- a/src/db/upnp/Directory.cxx +++ b/src/db/upnp/Directory.cxx @@ -151,7 +151,7 @@ protected: { if ((!strcmp(name, "container") || !strcmp(name, "item")) && checkobjok()) - m_dir.objects.push_back(m_tobj); + m_dir.objects.push_back(std::move(m_tobj)); m_path.pop_back(); } diff --git a/src/db/upnp/Directory.hxx b/src/db/upnp/Directory.hxx index 3324b2232..80b52ff2b 100644 --- a/src/db/upnp/Directory.hxx +++ b/src/db/upnp/Directory.hxx @@ -37,8 +37,8 @@ public: std::vector objects; gcc_pure - const UPnPDirObject *FindObject(const char *name) const { - for (const auto &o : objects) + UPnPDirObject *FindObject(const char *name) { + for (auto &o : objects) if (o.name == name) return &o; diff --git a/src/db/upnp/Object.hxx b/src/db/upnp/Object.hxx index 1346c15d4..1d32d0401 100644 --- a/src/db/upnp/Object.hxx +++ b/src/db/upnp/Object.hxx @@ -70,6 +70,10 @@ public: */ int duration; + UPnPDirObject() = default; + UPnPDirObject(UPnPDirObject &&) = default; + UPnPDirObject &operator=(UPnPDirObject &&) = default; + /** Get named property * @param property name (e.g. upnp:artist, upnp:album, * upnp:originalTrackNumber, upnp:genre). Use m_title instead