Address PR comments

This commit is contained in:
JCW
2026-04-01 21:04:20 +01:00
parent f2edebd919
commit 9c23371c46
2 changed files with 15 additions and 23 deletions

View File

@@ -13,6 +13,7 @@
#include <mutex>
#include <thread>
#include <type_traits>
#include <utility>
#include <vector>
namespace xrpl {
@@ -97,19 +98,6 @@ public:
del(key_type const& key, bool valid);
public:
/** Replace aliased objects with originals.
Due to concurrency it is possible for two separate objects with
the same content and referring to the same unique "thing" to exist.
These routines eliminate the duplicate and perform a replacement
as needed.
@param key The key corresponding to the object
@param data A shared pointer to the data corresponding to the object.
@return `true` If the key already existed.
*/
/** Replace the cache entry with the caller's data. */
bool
canonicalize_replace_cache(key_type const& key, SharedPointerType const& data);

View File

@@ -318,21 +318,25 @@ inline std::pair<
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
touchOrInsert(key_type const& key, SharedPointerType const& data)
{
auto [it, inserted] = m_cache.emplace(
std::piecewise_construct,
std::forward_as_tuple(key),
std::forward_as_tuple(m_clock.now(), data));
auto cit = m_cache.find(key);
bool inserted = false;
if (inserted)
if (cit == m_cache.end())
{
inserted = true;
auto emplaceResult = m_cache.emplace(
std::piecewise_construct,
std::forward_as_tuple(key),
std::forward_as_tuple(m_clock.now(), data));
++m_cache_count;
}
else
{
it->second.touch(m_clock.now());
cit = emplaceResult.first;
return {cit, inserted};
}
return {it, inserted};
cit->second.touch(m_clock.now());
return {cit, inserted};
}
template <