table: ensure NameTree::lookup(tableEntry) does not return nullptr

NameTree::lookup(tableEntry) is always equivalent to NameTree::lookup(Name).
NameTree::getEntry(tableEntry) should be used when inserting new name tree entry is undesired.

refs #3687

Change-Id: I0b17cd07dde83341976cfe66c85855dfb2fa6e89
diff --git a/daemon/table/measurements.cpp b/daemon/table/measurements.cpp
index 922c9cd..b2e8637 100644
--- a/daemon/table/measurements.cpp
+++ b/daemon/table/measurements.cpp
@@ -68,12 +68,6 @@
 Measurements::get(const fib::Entry& fibEntry)
 {
   shared_ptr<name_tree::Entry> nte = m_nameTree.lookup(fibEntry);
-  if (nte == nullptr) {
-    // must be Fib::s_emptyEntry that is unattached
-    BOOST_ASSERT(fibEntry.getPrefix().empty());
-    nte = m_nameTree.lookup(fibEntry.getPrefix());
-  }
-
   BOOST_ASSERT(nte != nullptr);
   return this->get(*nte);
 }
@@ -93,7 +87,7 @@
     return nullptr;
   }
 
-  shared_ptr<name_tree::Entry> nteChild = m_nameTree.lookup(child);
+  shared_ptr<name_tree::Entry> nteChild = m_nameTree.getEntry(child);
   name_tree::Entry* nte = nteChild->getParent();
   BOOST_ASSERT(nte != nullptr);
   return &this->get(*nte);
@@ -123,25 +117,20 @@
 Entry*
 Measurements::findLongestPrefixMatch(const pit::Entry& pitEntry, const EntryPredicate& pred) const
 {
-  shared_ptr<name_tree::Entry> nte = m_nameTree.lookup(pitEntry);
-  BOOST_ASSERT(nte != nullptr);
-  return this->findLongestPrefixMatchImpl(*nte, pred);
+  return this->findLongestPrefixMatchImpl(pitEntry, pred);
 }
 
 Entry*
 Measurements::findExactMatch(const Name& name) const
 {
-  shared_ptr<name_tree::Entry> nte = m_nameTree.lookup(name);
-  if (nte != nullptr) {
-    return nte->getMeasurementsEntry();
-  }
-  return nullptr;
+  const name_tree::Entry* nte = m_nameTree.findExactMatch(name);
+  return nte == nullptr ? nullptr : nte->getMeasurementsEntry();
 }
 
 void
 Measurements::extendLifetime(Entry& entry, const time::nanoseconds& lifetime)
 {
-  shared_ptr<name_tree::Entry> nte = m_nameTree.lookup(entry);
+  shared_ptr<name_tree::Entry> nte = m_nameTree.getEntry(entry);
   BOOST_ASSERT(nte != nullptr);
 
   time::steady_clock::TimePoint expiry = time::steady_clock::now() + lifetime;
@@ -158,7 +147,7 @@
 void
 Measurements::cleanup(Entry& entry)
 {
-  shared_ptr<name_tree::Entry> nte = m_nameTree.lookup(entry);
+  shared_ptr<name_tree::Entry> nte = m_nameTree.getEntry(entry);
   BOOST_ASSERT(nte != nullptr);
 
   nte->setMeasurementsEntry(nullptr);