mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-01 00:15:51 +00:00
Optimize for the more common case.
This commit is contained in:
@@ -286,6 +286,14 @@ boost::shared_ptr<c_Data> TaggedCache<c_Key, c_Data>::fetch(const key_type& key)
|
|||||||
{ // fetch us a shared pointer to the stored data object
|
{ // fetch us a shared pointer to the stored data object
|
||||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||||
|
|
||||||
|
// Is it in the cache?
|
||||||
|
cache_iterator cit = mCache.find(key);
|
||||||
|
if (cit != mCache.end())
|
||||||
|
{
|
||||||
|
cit->second.first = time(NULL); // Yes, refresh
|
||||||
|
return cit->second.second;
|
||||||
|
}
|
||||||
|
|
||||||
// Is it in the map?
|
// Is it in the map?
|
||||||
map_iterator mit = mMap.find(key);
|
map_iterator mit = mMap.find(key);
|
||||||
if (mit == mMap.end())
|
if (mit == mMap.end())
|
||||||
@@ -298,13 +306,8 @@ boost::shared_ptr<c_Data> TaggedCache<c_Key, c_Data>::fetch(const key_type& key)
|
|||||||
return cachedData;
|
return cachedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Valid in map, is it in the cache?
|
// Put it back in the cache
|
||||||
cache_iterator cit = mCache.find(key);
|
mCache.insert(cache_pair(key, cache_entry(time(NULL), cachedData)));
|
||||||
if (cit != mCache.end())
|
|
||||||
cit->second.first = time(NULL); // Yes, refresh
|
|
||||||
else // No, add to cache
|
|
||||||
mCache.insert(cache_pair(key, cache_entry(time(NULL), cachedData)));
|
|
||||||
|
|
||||||
return cachedData;
|
return cachedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user