Remove unrelated optimisation to make the PR easier to review

Signed-off-by: JCW <a1q123456@users.noreply.github.com>
This commit is contained in:
JCW
2026-03-18 21:45:22 +00:00
parent bf4dc342c6
commit 95969cb95e
2 changed files with 25 additions and 12 deletions

View File

@@ -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(

View File

@@ -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());
}