Improve and simplify code with modern C++ features
Change-Id: I83bf5513c2a1f90ba5a59e93c473306864b27d94
diff --git a/daemon/table/dead-nonce-list.cpp b/daemon/table/dead-nonce-list.cpp
index d732a90..144e68e 100644
--- a/daemon/table/dead-nonce-list.cpp
+++ b/daemon/table/dead-nonce-list.cpp
@@ -31,8 +31,8 @@
NFD_LOG_INIT(DeadNonceList);
-const time::nanoseconds DeadNonceList::DEFAULT_LIFETIME = time::seconds(6);
-const time::nanoseconds DeadNonceList::MIN_LIFETIME = time::milliseconds(1);
+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);
@@ -58,9 +58,8 @@
m_queue.push_back(MARK);
}
- m_markEvent = scheduler::schedule(m_markInterval, bind(&DeadNonceList::mark, this));
- m_adjustCapacityEvent = scheduler::schedule(m_adjustCapacityInterval,
- bind(&DeadNonceList::adjustCapacity, this));
+ m_markEvent = scheduler::schedule(m_markInterval, [this] { mark(); });
+ m_adjustCapacityEvent = scheduler::schedule(m_adjustCapacityInterval, [this] { adjustCapacity(); });
}
DeadNonceList::~DeadNonceList()
@@ -125,15 +124,13 @@
NFD_LOG_TRACE("mark nMarks=" << nMarks);
- scheduler::schedule(m_markInterval, bind(&DeadNonceList::mark, this));
+ m_markEvent = scheduler::schedule(m_markInterval, [this] { mark(); });
}
void
DeadNonceList::adjustCapacity()
{
- std::pair<std::multiset<size_t>::iterator, std::multiset<size_t>::iterator> equalRange =
- m_actualMarkCounts.equal_range(EXPECTED_MARK_COUNT);
-
+ auto equalRange = m_actualMarkCounts.equal_range(EXPECTED_MARK_COUNT);
if (equalRange.second == m_actualMarkCounts.begin()) {
// all counts are above expected count, adjust down
m_capacity = std::max(MIN_CAPACITY,
@@ -148,11 +145,9 @@
}
m_actualMarkCounts.clear();
-
this->evictEntries();
- m_adjustCapacityEvent = scheduler::schedule(m_adjustCapacityInterval,
- bind(&DeadNonceList::adjustCapacity, this));
+ m_adjustCapacityEvent = scheduler::schedule(m_adjustCapacityInterval, [this] { adjustCapacity(); });
}
void