table: optimize removal of PIT in-records
Most call sites already have an iterator that can be used directly,
so change deleteInRecord() to accept an iterator instead of doing
another list lookup.
Change-Id: Ie097f4bc4b13e7428e0580ed7cf4dcb506a009f7
diff --git a/daemon/table/pit-entry.cpp b/daemon/table/pit-entry.cpp
index b302c28..194106d 100644
--- a/daemon/table/pit-entry.cpp
+++ b/daemon/table/pit-entry.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California,
+ * Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -51,7 +51,7 @@
Entry::getInRecord(const Face& face)
{
return std::find_if(m_inRecords.begin(), m_inRecords.end(),
- [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
+ [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
}
InRecordCollection::iterator
@@ -60,7 +60,7 @@
BOOST_ASSERT(this->canMatch(interest));
auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
- [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
+ [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
if (it == m_inRecords.end()) {
m_inRecords.emplace_front(face);
it = m_inRecords.begin();
@@ -71,13 +71,10 @@
}
void
-Entry::deleteInRecord(const Face& face)
+Entry::deleteInRecord(InRecordCollection::const_iterator pos)
{
- auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
- [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
- if (it != m_inRecords.end()) {
- m_inRecords.erase(it);
- }
+ BOOST_ASSERT(pos != m_inRecords.end());
+ m_inRecords.erase(pos);
}
void
@@ -90,7 +87,7 @@
Entry::getOutRecord(const Face& face)
{
return std::find_if(m_outRecords.begin(), m_outRecords.end(),
- [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
+ [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
}
OutRecordCollection::iterator
@@ -99,7 +96,7 @@
BOOST_ASSERT(this->canMatch(interest));
auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
- [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
+ [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
if (it == m_outRecords.end()) {
m_outRecords.emplace_front(face);
it = m_outRecords.begin();
@@ -113,7 +110,7 @@
Entry::deleteOutRecord(const Face& face)
{
auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
- [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
+ [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
if (it != m_outRecords.end()) {
m_outRecords.erase(it);
}
diff --git a/daemon/table/pit-entry.hpp b/daemon/table/pit-entry.hpp
index 82ed272..d6f304b 100644
--- a/daemon/table/pit-entry.hpp
+++ b/daemon/table/pit-entry.hpp
@@ -93,10 +93,11 @@
canMatch(const Interest& interest, size_t nEqualNameComps = 0) const;
public: // in-record
- /** \return collection of in-records
+ /**
+ * \brief Returns the collection of in-records.
*/
const InRecordCollection&
- getInRecords() const
+ getInRecords() const noexcept
{
return m_inRecords;
}
@@ -107,62 +108,68 @@
* This implies the entry is new or has been satisfied or Nacked.
*/
bool
- hasInRecords() const
+ hasInRecords() const noexcept
{
return !m_inRecords.empty();
}
InRecordCollection::iterator
- in_begin()
+ in_begin() noexcept
{
return m_inRecords.begin();
}
InRecordCollection::const_iterator
- in_begin() const
+ in_begin() const noexcept
{
return m_inRecords.begin();
}
InRecordCollection::iterator
- in_end()
+ in_end() noexcept
{
return m_inRecords.end();
}
InRecordCollection::const_iterator
- in_end() const
+ in_end() const noexcept
{
return m_inRecords.end();
}
- /** \brief Get the in-record for \p face.
- * \return an iterator to the in-record, or in_end() if it does not exist
+ /**
+ * \brief Get the in-record for \p face.
+ * \return an iterator to the in-record, or in_end() if it does not exist
*/
InRecordCollection::iterator
getInRecord(const Face& face);
- /** \brief Insert or update an in-record.
- * \return an iterator to the new or updated in-record
+ /**
+ * \brief Insert or update an in-record.
+ * \return an iterator to the new or updated in-record
*/
InRecordCollection::iterator
insertOrUpdateInRecord(Face& face, const Interest& interest);
- /** \brief Delete the in-record for \p face if it exists.
+ /**
+ * \brief Removes the in-record at position \p pos.
+ * \param pos iterator to the in-record to remove; must be valid and dereferenceable.
*/
void
- deleteInRecord(const Face& face);
+ deleteInRecord(InRecordCollection::const_iterator pos);
- /** \brief Delete all in-records.
+ /**
+ * \brief Removes all in-records.
*/
void
clearInRecords();
public: // out-record
- /** \return collection of in-records
+ /**
+ * \brief Returns the collection of out-records.
*/
const OutRecordCollection&
- getOutRecords() const
+ getOutRecords() const noexcept
{
return m_outRecords;
}
@@ -174,48 +181,51 @@
* This implies the Interest has not been forwarded.
*/
bool
- hasOutRecords() const
+ hasOutRecords() const noexcept
{
return !m_outRecords.empty();
}
OutRecordCollection::iterator
- out_begin()
+ out_begin() noexcept
{
return m_outRecords.begin();
}
OutRecordCollection::const_iterator
- out_begin() const
+ out_begin() const noexcept
{
return m_outRecords.begin();
}
OutRecordCollection::iterator
- out_end()
+ out_end() noexcept
{
return m_outRecords.end();
}
OutRecordCollection::const_iterator
- out_end() const
+ out_end() const noexcept
{
return m_outRecords.end();
}
- /** \brief Get the out-record for \p face.
- * \return an iterator to the out-record, or out_end() if it does not exist
+ /**
+ * \brief Get the out-record for \p face.
+ * \return an iterator to the out-record, or out_end() if it does not exist
*/
OutRecordCollection::iterator
getOutRecord(const Face& face);
- /** \brief Insert or update an out-record.
- * \return an iterator to the new or updated out-record
+ /**
+ * \brief Insert or update an out-record.
+ * \return an iterator to the new or updated out-record
*/
OutRecordCollection::iterator
insertOrUpdateOutRecord(Face& face, const Interest& interest);
- /** \brief Delete the out-record for \p face if it exists.
+ /**
+ * \brief Delete the out-record for \p face if it exists.
*/
void
deleteOutRecord(const Face& face);
@@ -232,7 +242,7 @@
bool isSatisfied = false;
/** \brief Data freshness period.
- * \note This field is meaningful only if isSatisfied is true
+ * \note This field is meaningful only if #isSatisfied is true
*/
time::milliseconds dataFreshnessPeriod = 0_ms;
diff --git a/daemon/table/pit.cpp b/daemon/table/pit.cpp
index 4ebdefb..b731df0 100644
--- a/daemon/table/pit.cpp
+++ b/daemon/table/pit.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California,
+ * Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -115,7 +115,10 @@
{
BOOST_ASSERT(entry != nullptr);
- entry->deleteInRecord(face);
+ auto in = entry->getInRecord(face);
+ if (in != entry->in_end()) {
+ entry->deleteInRecord(in);
+ }
entry->deleteOutRecord(face);
/// \todo decide whether to delete PIT entry if there's no more in/out-record left