main: Match getSubTrees* to GetAncestors pattern
getSubTrees, getSubTreePaths and GetAncestors have a code snippet that's
very similar. Unify them so that they are easier to read.
For the ret vector being declared further down, it's better practice to
declare variables closer to where it's going to be used since
we wouldn't have needed ret if we error out early.
Tested: The code is only syntatically different. Tested with the
following commit in more depth.
Signed-off-by: Brandon Kim <brandonkim@google.com>
Change-Id: Ib449ab4ffab502c801040cf6bce28b30507d8e0b
diff --git a/src/main.cpp b/src/main.cpp
index 9ceb9ab..23f3c5f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -468,7 +468,13 @@
for (const auto& objectPath : interfaceMap)
{
const auto& thisPath = objectPath.first;
- if (boost::starts_with(reqPath, thisPath) && (reqPath != thisPath))
+
+ if (reqPath == thisPath)
+ {
+ continue;
+ }
+
+ if (boost::starts_with(reqPath, thisPath))
{
if (interfaces.empty())
{
@@ -538,7 +544,6 @@
}
// Interfaces need to be sorted for intersect to function
std::sort(interfaces.begin(), interfaces.end());
- std::vector<InterfaceMapType::value_type> ret;
if (boost::ends_with(reqPath, "/"))
{
@@ -550,6 +555,7 @@
ResourceNotFound();
}
+ std::vector<InterfaceMapType::value_type> ret;
for (const auto& objectPath : interfaceMap)
{
const auto& thisPath = objectPath.first;
@@ -593,7 +599,6 @@
}
// Interfaces need to be sorted for intersect to function
std::sort(interfaces.begin(), interfaces.end());
- std::vector<std::string> ret;
if (boost::ends_with(reqPath, "/"))
{
@@ -605,6 +610,7 @@
ResourceNotFound();
}
+ std::vector<std::string> ret;
for (const auto& objectPath : interfaceMap)
{
const auto& thisPath = objectPath.first;