From 423635d2ef6d5d15a2e0ec74c7749ae412bcd4d5 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 14 May 2013 18:25:47 -0700 Subject: [PATCH] Faster publishing of order book changes to book listeners --- src/cpp/ripple/NetworkOPs.h | 2 ++ src/cpp/ripple/OrderBookDB.cpp | 17 ++++++++++------- src/cpp/ripple/WSConnection.h | 7 +++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/cpp/ripple/NetworkOPs.h b/src/cpp/ripple/NetworkOPs.h index 24a212c82e..c18f8b55c1 100644 --- a/src/cpp/ripple/NetworkOPs.h +++ b/src/cpp/ripple/NetworkOPs.h @@ -52,6 +52,8 @@ public: virtual ~InfoSub(); virtual void send(const Json::Value& jvObj, bool broadcast) = 0; + virtual void send(const Json::Value& jvObj, const std::string& sObj, bool broadcast) + { send(jvObj, broadcast); } uint64 getSeq() { diff --git a/src/cpp/ripple/OrderBookDB.cpp b/src/cpp/ripple/OrderBookDB.cpp index 0a7be27834..94d659d3e8 100644 --- a/src/cpp/ripple/OrderBookDB.cpp +++ b/src/cpp/ripple/OrderBookDB.cpp @@ -167,13 +167,13 @@ void OrderBookDB::processTxn(Ledger::ref ledger, const ALTransaction& alTx, Json const STObject* data = dynamic_cast(node.peekAtPField(*field)); if (data) { - STAmount takerGets = data->getFieldAmount(sfTakerGets); - uint160 currencyGets = takerGets.getCurrency(); - uint160 issuerGets = takerGets.getIssuer(); + const STAmount& takerGets = data->getFieldAmount(sfTakerGets); + const uint160& currencyGets = takerGets.getCurrency(); + const uint160& issuerGets = takerGets.getIssuer(); - STAmount takerPays = data->getFieldAmount(sfTakerPays); - uint160 currencyPays = takerPays.getCurrency(); - uint160 issuerPays = takerPays.getIssuer(); + const STAmount& takerPays = data->getFieldAmount(sfTakerPays); + const uint160& currencyPays = takerPays.getCurrency(); + const uint160& issuerPays = takerPays.getIssuer(); // determine the OrderBook BookListeners::pointer book = @@ -206,6 +206,9 @@ void BookListeners::removeSubscriber(uint64 seq) void BookListeners::publish(Json::Value& jvObj) { + Json::FastWriter jfwWriter; + std::string sObj = jfwWriter.write(jvObj); + boost::recursive_mutex::scoped_lock sl(mLock); NetworkOPs::subMapType::const_iterator it = mListeners.begin(); while (it != mListeners.end()) @@ -213,7 +216,7 @@ void BookListeners::publish(Json::Value& jvObj) InfoSub::pointer p = it->second.lock(); if (p) { - p->send(jvObj, true); + p->send(jvObj, sObj, true); ++it; } else diff --git a/src/cpp/ripple/WSConnection.h b/src/cpp/ripple/WSConnection.h index f27ea00b26..baa8e3ab89 100644 --- a/src/cpp/ripple/WSConnection.h +++ b/src/cpp/ripple/WSConnection.h @@ -95,6 +95,13 @@ public: mHandler->send(ptr, jvObj, broadcast); } + void send(const Json::Value& jvObj, const std::string& sObj, bool broadcast) + { + connection_ptr ptr = mConnection.lock(); + if (ptr) + mHandler->send(ptr, sObj, broadcast); + } + // Utilities Json::Value invokeCommand(Json::Value& jvRequest) {