table: cleanupOnFaceRemoval doesn't rely on shared_ptr<name_tree::Entry> anymore
refs #3687
Change-Id: I3901f053bf370ca5a19a0fea72aec8eb58fcfe10
diff --git a/daemon/table/cleanup.cpp b/daemon/table/cleanup.cpp
index 8317099..c31ccc4 100644
--- a/daemon/table/cleanup.cpp
+++ b/daemon/table/cleanup.cpp
@@ -30,7 +30,7 @@
void
cleanupOnFaceRemoval(NameTree& nt, Fib& fib, Pit& pit, const Face& face)
{
- std::multimap<size_t, weak_ptr<name_tree::Entry>> maybeEmptyNtes;
+ std::multimap<size_t, const name_tree::Entry*> maybeEmptyNtes;
// visit FIB and PIT entries in one pass of NameTree enumeration
for (const name_tree::Entry& nte : nt) {
@@ -43,19 +43,19 @@
pit.deleteInOutRecords(pitEntry, face);
}
- if (nte.getFibEntry() == nullptr && !nte.hasPitEntries()) {
- maybeEmptyNtes.emplace(nte.getName().size(), const_pointer_cast<name_tree::Entry>(nte.shared_from_this()));
+ if (!nte.hasTableEntries()) {
+ maybeEmptyNtes.emplace(nte.getName().size(), &nte);
}
}
// try to erase longer names first, so that children are erased before parent is checked
for (auto i = maybeEmptyNtes.rbegin(); i != maybeEmptyNtes.rend(); ++i) {
- shared_ptr<name_tree::Entry> nte = i->second.lock();
- // nte may have been erased when its last child is erased
- if (nte != nullptr) {
- nt.eraseIfEmpty(nte.get());
- }
+ nt.eraseIfEmpty(const_cast<name_tree::Entry*>(i->second), false);
}
+
+ BOOST_ASSERT(nt.size() == 0 ||
+ std::none_of(nt.begin(), nt.end(),
+ [] (const name_tree::Entry& nte) { return nte.isEmpty(); }));
}
} // namespace nfd