aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-21 23:32:42 +0100
committerMax Kellermann <max@duempel.org>2014-01-21 23:32:42 +0100
commitaa1eb2f40dc7fdef6490634ab82c6f0f82ccfd79 (patch)
treed1e7ab43a3de05c0c0179af2ec055d6a4daf7b09
parent7260d7883ce98299126b850e6c1559d2597914fa (diff)
downloadmpd-aa1eb2f40dc7fdef6490634ab82c6f0f82ccfd79.tar.gz
mpd-aa1eb2f40dc7fdef6490634ab82c6f0f82ccfd79.tar.xz
mpd-aa1eb2f40dc7fdef6490634ab82c6f0f82ccfd79.zip
db/upnp: use iterator in Namei()
-rw-r--r--src/db/UpnpDatabasePlugin.cxx9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/db/UpnpDatabasePlugin.cxx b/src/db/UpnpDatabasePlugin.cxx
index 0307a984f..7e2bfb2f6 100644
--- a/src/db/UpnpDatabasePlugin.cxx
+++ b/src/db/UpnpDatabasePlugin.cxx
@@ -480,13 +480,14 @@ UpnpDatabase::Namei(ContentDirectoryService &server,
std::string objid(rootid);
// Walk the path elements, read each directory and try to find the next one
- for (unsigned int i = 0; i < vpath.size(); i++) {
+ for (auto i = vpath.begin(), end = vpath.end(), last = std::prev(end);
+ i != end; ++i) {
UPnPDirContent dirbuf;
if (!server.readDir(handle, objid.c_str(), dirbuf, error))
return false;
// Look for the name in the sub-container list
- UPnPDirObject *child = dirbuf.FindObject(vpath[i].c_str());
+ UPnPDirObject *child = dirbuf.FindObject(i->c_str());
if (child == nullptr)
break;
@@ -497,7 +498,7 @@ UpnpDatabase::Namei(ContentDirectoryService &server,
case UPnPDirObject::Type::CONTAINER:
objid = child->m_id; // Next readdir target
- if (i == vpath.size() - 1) {
+ if (i == last) {
// The last element in the path was found and it's
// a container, we're done
odirent = std::move(*child);
@@ -508,7 +509,7 @@ UpnpDatabase::Namei(ContentDirectoryService &server,
case UPnPDirObject::Type::ITEM:
// If this is the last path elt, we found the target,
// else it does not exist
- if (i == vpath.size() - 1) {
+ if (i == last) {
odirent = std::move(*child);
return true;
} else {