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