table: DeadNonceList code cleanup/modernization
Change-Id: I7d2bb8982b60b138c979470406b0a607301f2768
diff --git a/daemon/table/dead-nonce-list.cpp b/daemon/table/dead-nonce-list.cpp
index 142ddea..c89e9cc 100644
--- a/daemon/table/dead-nonce-list.cpp
+++ b/daemon/table/dead-nonce-list.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2020, Regents of the University of California,
+ * Copyright (c) 2014-2021, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -32,16 +32,16 @@
NFD_LOG_INIT(DeadNonceList);
-const time::nanoseconds DeadNonceList::DEFAULT_LIFETIME = 6_s;
-const time::nanoseconds DeadNonceList::MIN_LIFETIME = 1_ms;
-const size_t DeadNonceList::INITIAL_CAPACITY = 1 << 7;
-const size_t DeadNonceList::MIN_CAPACITY = 1 << 3;
-const size_t DeadNonceList::MAX_CAPACITY = 1 << 24;
-const DeadNonceList::Entry DeadNonceList::MARK = 0;
-const size_t DeadNonceList::EXPECTED_MARK_COUNT = 5;
-const double DeadNonceList::CAPACITY_UP = 1.2;
-const double DeadNonceList::CAPACITY_DOWN = 0.9;
-const size_t DeadNonceList::EVICT_LIMIT = 1 << 6;
+const time::nanoseconds DeadNonceList::DEFAULT_LIFETIME;
+const time::nanoseconds DeadNonceList::MIN_LIFETIME;
+const size_t DeadNonceList::INITIAL_CAPACITY;
+const size_t DeadNonceList::MIN_CAPACITY;
+const size_t DeadNonceList::MAX_CAPACITY;
+const DeadNonceList::Entry DeadNonceList::MARK;
+const size_t DeadNonceList::EXPECTED_MARK_COUNT;
+const double DeadNonceList::CAPACITY_UP;
+const double DeadNonceList::CAPACITY_DOWN;
+const size_t DeadNonceList::EVICT_LIMIT;
DeadNonceList::DeadNonceList(time::nanoseconds lifetime)
: m_lifetime(lifetime)
@@ -61,12 +61,6 @@
m_markEvent = getScheduler().schedule(m_markInterval, [this] { mark(); });
m_adjustCapacityEvent = getScheduler().schedule(m_adjustCapacityInterval, [this] { adjustCapacity(); });
-}
-
-DeadNonceList::~DeadNonceList()
-{
- m_markEvent.cancel();
- m_adjustCapacityEvent.cancel();
BOOST_ASSERT_MSG(DEFAULT_LIFETIME >= MIN_LIFETIME, "DEFAULT_LIFETIME is too small");
static_assert(INITIAL_CAPACITY >= MIN_CAPACITY, "INITIAL_CAPACITY is too small");
@@ -83,7 +77,7 @@
size_t
DeadNonceList::size() const
{
- return m_queue.size() - this->countMarks();
+ return m_queue.size() - countMarks();
}
bool
@@ -99,13 +93,13 @@
Entry entry = DeadNonceList::makeEntry(name, nonce);
m_queue.push_back(entry);
- this->evictEntries();
+ evictEntries();
}
DeadNonceList::Entry
DeadNonceList::makeEntry(const Name& name, Interest::Nonce nonce)
{
- Block nameWire = name.wireEncode();
+ const auto& nameWire = name.wireEncode();
uint32_t n;
std::memcpy(&n, nonce.data(), sizeof(n));
return CityHash64WithSeed(reinterpret_cast<const char*>(nameWire.wire()), nameWire.size(), n);
@@ -121,7 +115,7 @@
DeadNonceList::mark()
{
m_queue.push_back(MARK);
- size_t nMarks = this->countMarks();
+ size_t nMarks = countMarks();
m_actualMarkCounts.insert(nMarks);
NFD_LOG_TRACE("mark nMarks=" << nMarks);
@@ -145,7 +139,7 @@
}
m_actualMarkCounts.clear();
- this->evictEntries();
+ evictEntries();
m_adjustCapacityEvent = getScheduler().schedule(m_adjustCapacityInterval, [this] { adjustCapacity(); });
}
@@ -153,11 +147,11 @@
void
DeadNonceList::evictEntries()
{
- ssize_t nOverCapacity = m_queue.size() - m_capacity;
- if (nOverCapacity <= 0) // not over capacity
+ if (m_queue.size() <= m_capacity) // not over capacity
return;
- for (ssize_t nEvict = std::min<ssize_t>(nOverCapacity, EVICT_LIMIT); nEvict > 0; --nEvict) {
+ auto nEvict = std::min(m_queue.size() - m_capacity, EVICT_LIMIT);
+ for (; nEvict > 0; --nEvict) {
m_queue.erase(m_queue.begin());
}
BOOST_ASSERT(m_queue.size() >= m_capacity);