Browse Source

Merge #8353: Trivial: tiny c++11 refactors

c784086 use std::map::emplace() instead of std::map::insert() (whythat)
5e187e7 use c++11 std::unique_ptr instead of boost::shared_ptr (whythat)
947913f use std::map::erase(const_iterator, const_iterator) to get non-constant iterator (whythat)
0.14
Wladimir J. van der Laan 8 years ago
parent
commit
3859072963
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 7
      src/limitedmap.h
  2. 9
      src/rpc/server.cpp

7
src/limitedmap.h

@ -66,8 +66,11 @@ public:
} }
void update(const_iterator itIn, const mapped_type& v) void update(const_iterator itIn, const mapped_type& v)
{ {
// TODO: When we switch to C++11, use map.erase(itIn, itIn) to get the non-const iterator. // Using map::erase() with empty range instead of map::find() to get a non-const iterator,
iterator itTarget = map.find(itIn->first); // since it is a constant time operation in C++11. For more details, see
// https://stackoverflow.com/questions/765148/how-to-remove-constness-of-const-iterator
iterator itTarget = map.erase(itIn, itIn);
if (itTarget == map.end()) if (itTarget == map.end())
return; return;
std::pair<rmap_iterator, rmap_iterator> itPair = rmap.equal_range(itTarget->second); std::pair<rmap_iterator, rmap_iterator> itPair = rmap.equal_range(itTarget->second);

9
src/rpc/server.cpp

@ -25,6 +25,8 @@
#include <boost/thread.hpp> #include <boost/thread.hpp>
#include <boost/algorithm/string/case_conv.hpp> // for to_upper() #include <boost/algorithm/string/case_conv.hpp> // for to_upper()
#include <memory> // for unique_ptr
using namespace RPCServer; using namespace RPCServer;
using namespace std; using namespace std;
@ -34,9 +36,8 @@ static std::string rpcWarmupStatus("RPC server started");
static CCriticalSection cs_rpcWarmup; static CCriticalSection cs_rpcWarmup;
/* Timer-creating functions */ /* Timer-creating functions */
static RPCTimerInterface* timerInterface = NULL; static RPCTimerInterface* timerInterface = NULL;
/* Map of name to timer. /* Map of name to timer. */
* @note Can be changed to std::unique_ptr when C++11 */ static std::map<std::string, std::unique_ptr<RPCTimerBase> > deadlineTimers;
static std::map<std::string, boost::shared_ptr<RPCTimerBase> > deadlineTimers;
static struct CRPCSignals static struct CRPCSignals
{ {
@ -490,7 +491,7 @@ void RPCRunLater(const std::string& name, boost::function<void(void)> func, int6
throw JSONRPCError(RPC_INTERNAL_ERROR, "No timer handler registered for RPC"); throw JSONRPCError(RPC_INTERNAL_ERROR, "No timer handler registered for RPC");
deadlineTimers.erase(name); deadlineTimers.erase(name);
LogPrint("rpc", "queue run of timer %s in %i seconds (using %s)\n", name, nSeconds, timerInterface->Name()); LogPrint("rpc", "queue run of timer %s in %i seconds (using %s)\n", name, nSeconds, timerInterface->Name());
deadlineTimers.insert(std::make_pair(name, boost::shared_ptr<RPCTimerBase>(timerInterface->NewTimer(func, nSeconds*1000)))); deadlineTimers.emplace(name, std::unique_ptr<RPCTimerBase>(timerInterface->NewTimer(func, nSeconds*1000)));
} }
CRPCTable tableRPC; CRPCTable tableRPC;

Loading…
Cancel
Save