Reduce usage of std::bind()
C++14 lambdas are easier to read, easier to debug,
and can usually be better optimized by the compiler.
Change-Id: I294f275904f91942a8de946fe63e77078a7608a6
diff --git a/daemon/rib/fib-updater.cpp b/daemon/rib/fib-updater.cpp
index 6e600e4..5208e61 100644
--- a/daemon/rib/fib-updater.cpp
+++ b/daemon/rib/fib-updater.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, 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,
@@ -95,13 +95,13 @@
const Name& prefix = update.getName();
const Route& route = update.getRoute();
- Rib::const_iterator it = m_rib.find(prefix);
+ auto it = m_rib.find(prefix);
// Name prefix exists
if (it != m_rib.end()) {
shared_ptr<const RibEntry> entry(it->second);
- RibEntry::const_iterator existingRoute = entry->findRoute(route);
+ auto existingRoute = entry->findRoute(route);
// Route will be new
if (existingRoute == entry->end()) {
@@ -114,8 +114,7 @@
// Route already exists
RibEntry entryCopy = *entry;
- Route& routeToUpdate = *(entryCopy.findRoute(route));
-
+ Route& routeToUpdate = *entryCopy.findRoute(route);
routeToUpdate.flags = route.flags;
routeToUpdate.cost = route.cost;
routeToUpdate.expires = route.expires;
@@ -149,16 +148,14 @@
const Name& prefix = update.getName();
const Route& route = update.getRoute();
- Rib::const_iterator ribIt = m_rib.find(prefix);
+ auto ribIt = m_rib.find(prefix);
// Name prefix exists
if (ribIt != m_rib.end()) {
shared_ptr<const RibEntry> entry(ribIt->second);
-
const bool hadCapture = entry->hasCapture();
- RibEntry::const_iterator existing = entry->findRoute(route);
-
+ auto existing = entry->findRoute(route);
if (existing != entry->end()) {
RibEntry temp = *entry;
@@ -240,8 +237,8 @@
.setName(update.name)
.setFaceId(update.faceId)
.setCost(update.cost),
- bind(&FibUpdater::onUpdateSuccess, this, update, onSuccess, onFailure),
- bind(&FibUpdater::onUpdateError, this, update, onSuccess, onFailure, _1, nTimeouts));
+ [=] (const auto&) { onUpdateSuccess(update, onSuccess, onFailure); },
+ [=] (const auto& resp) { onUpdateError(update, onSuccess, onFailure, resp, nTimeouts); });
}
void
@@ -254,12 +251,12 @@
ControlParameters()
.setName(update.name)
.setFaceId(update.faceId),
- bind(&FibUpdater::onUpdateSuccess, this, update, onSuccess, onFailure),
- bind(&FibUpdater::onUpdateError, this, update, onSuccess, onFailure, _1, nTimeouts));
+ [=] (const auto&) { onUpdateSuccess(update, onSuccess, onFailure); },
+ [=] (const auto& resp) { onUpdateError(update, onSuccess, onFailure, resp, nTimeouts); });
}
void
-FibUpdater::onUpdateSuccess(const FibUpdate update,
+FibUpdater::onUpdateSuccess(const FibUpdate& update,
const FibUpdateSuccessCallback& onSuccess,
const FibUpdateFailureCallback& onFailure)
{
@@ -280,7 +277,7 @@
}
void
-FibUpdater::onUpdateError(const FibUpdate update,
+FibUpdater::onUpdateError(const FibUpdate& update,
const FibUpdateSuccessCallback& onSuccess,
const FibUpdateFailureCallback& onFailure,
const ndn::nfd::ControlResponse& response, uint32_t nTimeouts)
@@ -310,14 +307,13 @@
}
void
-FibUpdater::addFibUpdate(FibUpdate update)
+FibUpdater::addFibUpdate(const FibUpdate& update)
{
FibUpdateList& updates = (update.faceId == m_batchFaceId) ? m_updatesForBatchFaceId :
m_updatesForNonBatchFaceId;
- // If an update with the same name and route already exists,
- // replace it
- FibUpdateList::iterator it = std::find_if(updates.begin(), updates.end(),
+ // If an update with the same name and route already exists, replace it
+ auto it = std::find_if(updates.begin(), updates.end(),
[&update] (const FibUpdate& other) {
return update.name == other.name && update.faceId == other.faceId;
});
@@ -400,7 +396,7 @@
// If there is an ancestor route which is the same as the new route, replace it
// with the new route
- Rib::RouteSet::iterator it = ancestorRoutes.find(route);
+ auto it = ancestorRoutes.find(route);
// There is a route that needs to be overwritten, erase and then replace
if (it != ancestorRoutes.end()) {
@@ -525,7 +521,7 @@
else {
// Look for an ancestor that was blocked previously
const Rib::RouteSet ancestorRoutes = m_rib.getAncestorRoutes(entry);
- Rib::RouteSet::iterator it = ancestorRoutes.find(route);
+ auto it = ancestorRoutes.find(route);
// If an ancestor is found, add it to children
if (it != ancestorRoutes.end()) {
@@ -616,7 +612,7 @@
if (!entry.hasCapture() && entry.getNRoutes() != 0) {
// If there is an ancestor route which is the same as the erased route, add that route
// to the current entry
- Rib::RouteSet::iterator it = ancestorRoutes.find(route);
+ auto it = ancestorRoutes.find(route);
if (it != ancestorRoutes.end()) {
addInheritedRoute(entry.getName(), *it);