mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
Remove unrelated optimisation to make the PR easier to review
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
This commit is contained in:
@@ -127,7 +127,8 @@ public:
|
||||
|
||||
@param key The key corresponding to the object
|
||||
@param data A shared pointer to the data corresponding to the object.
|
||||
@param replaceCallback Function that decides if cache should be replaced
|
||||
@param shouldReplaceCheckCb Function that decides if cache should be
|
||||
replaced
|
||||
|
||||
@return First item: `true` If the key already existed; Second item: The
|
||||
canonicalized item.
|
||||
@@ -137,7 +138,7 @@ public:
|
||||
canonicalize(
|
||||
key_type const& key,
|
||||
SharedPointerType const& data,
|
||||
R&& replaceCallback);
|
||||
R&& shouldReplaceCheckCb);
|
||||
|
||||
bool
|
||||
canonicalize_replace_cache(
|
||||
|
||||
@@ -435,27 +435,31 @@ TaggedCache<
|
||||
Entry& entry = cit->second;
|
||||
entry.touch(m_clock.now());
|
||||
|
||||
auto replaceEntryIfNecessary = [&] {
|
||||
bool shouldReplace = false;
|
||||
auto shouldReplace = [&] {
|
||||
if constexpr (std::is_invocable_r_v<bool, R>)
|
||||
{
|
||||
// The reason for this extra complexity is for intrusive
|
||||
// strong/weak combo getting a strong is relatively expensive
|
||||
// and not needed for many cases.
|
||||
shouldReplace = replaceCallback();
|
||||
return replaceCallback();
|
||||
}
|
||||
else
|
||||
{
|
||||
shouldReplace = replaceCallback(entry.ptr.getStrong());
|
||||
return replaceCallback(entry.ptr.getStrong());
|
||||
}
|
||||
|
||||
if (shouldReplace)
|
||||
entry.ptr = data;
|
||||
};
|
||||
|
||||
if (entry.isCached())
|
||||
{
|
||||
replaceEntryIfNecessary();
|
||||
if (shouldReplace())
|
||||
{
|
||||
entry.ptr = data;
|
||||
}
|
||||
else
|
||||
{
|
||||
data = entry.ptr.getStrong();
|
||||
}
|
||||
|
||||
return std::make_pair(true, entry.ptr.getStrong());
|
||||
}
|
||||
|
||||
@@ -463,8 +467,16 @@ TaggedCache<
|
||||
|
||||
if (cachedData)
|
||||
{
|
||||
replaceEntryIfNecessary();
|
||||
entry.ptr.convertToStrong();
|
||||
if (shouldReplace())
|
||||
{
|
||||
entry.ptr = data;
|
||||
}
|
||||
else
|
||||
{
|
||||
entry.ptr.convertToStrong();
|
||||
data = cachedData;
|
||||
}
|
||||
|
||||
++m_cache_count;
|
||||
return std::make_pair(true, entry.ptr.getStrong());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user