table: NameTree::findLongestPrefixMatch predicate

refs #1313

Change-Id: I759c8ddf9bc0fe5b970c979f69131a98b1ef32e4
diff --git a/daemon/table/measurements.cpp b/daemon/table/measurements.cpp
index e361aba..a5b107e 100644
--- a/daemon/table/measurements.cpp
+++ b/daemon/table/measurements.cpp
@@ -23,6 +23,12 @@
 {
 }
 
+static inline bool
+predicate_NameTreeEntry_hasMeasurementsEntry(const name_tree::Entry& entry)
+{
+  return static_cast<bool>(entry.getMeasurementsEntry());
+}
+
 shared_ptr<measurements::Entry>
 Measurements::get(const Name& name)
 {
@@ -63,12 +69,10 @@
 shared_ptr<measurements::Entry>
 Measurements::findLongestPrefixMatch(const Name& name) const
 {
-  shared_ptr<name_tree::Entry> nameTreeEntry = m_nameTree.findLongestPrefixMatch(name);
-  while (static_cast<bool>(nameTreeEntry))
-  {
-    if (static_cast<bool>(nameTreeEntry->getMeasurementsEntry()))
-      return nameTreeEntry->getMeasurementsEntry();
-    nameTreeEntry = nameTreeEntry->getParent();
+  shared_ptr<name_tree::Entry> nameTreeEntry =
+    m_nameTree.findLongestPrefixMatch(name, &predicate_NameTreeEntry_hasMeasurementsEntry);
+  if (static_cast<bool>(nameTreeEntry)) {
+    return nameTreeEntry->getMeasurementsEntry();
   }
   return shared_ptr<measurements::Entry>();
 }