From aa1eb2f40dc7fdef6490634ab82c6f0f82ccfd79 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 21 Jan 2014 23:32:42 +0100 Subject: db/upnp: use iterator in Namei() --- src/db/UpnpDatabasePlugin.cxx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') 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 { -- cgit v1.2.3