From 61623d6d75d5584cca46be9ae30f7171639765b2 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 21 Aug 2014 16:05:35 -0700 Subject: [PATCH] Improve parallelization of getRippleLines --- .../module/app/paths/RippleLineCache.cpp | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/ripple/module/app/paths/RippleLineCache.cpp b/src/ripple/module/app/paths/RippleLineCache.cpp index fb13a7b33..09f359a0e 100644 --- a/src/ripple/module/app/paths/RippleLineCache.cpp +++ b/src/ripple/module/app/paths/RippleLineCache.cpp @@ -27,15 +27,22 @@ RippleLineCache::RippleLineCache (Ledger::ref l) std::vector const& RippleLineCache::getRippleLines (Account const& accountID) { + + { + ScopedLockType sl (mLock); + + auto it = mRLMap.find (accountID); + if (it != mRLMap.end ()) + return it->second; + } + + // It's not in the cache, so build it + auto lines = ripple::getRippleStateItems (accountID, mLedger); + ScopedLockType sl (mLock); - auto it = mRLMap.find (accountID); - - if (it == mRLMap.end ()) - it = mRLMap.insert (std::make_pair ( - accountID, ripple::getRippleStateItems (accountID, mLedger))).first; - - return it->second; + // We must return a reference to the cached version + return mRLMap.emplace (accountID, std::move (lines)).first->second; } } // ripple