aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/structuredcachestore.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-05-06 23:32:35 +0200
committerDan Engelbrecht <[email protected]>2022-05-06 23:32:35 +0200
commit2f6461e3ed7851bc5592b6bc9efdfb0d973fe284 (patch)
treeea36e216b6437ef483a97e91ceb1e4d922ac1393 /zenserver/cache/structuredcachestore.cpp
parentreview feedback and cleanup (diff)
downloadzen-2f6461e3ed7851bc5592b6bc9efdfb0d973fe284.tar.xz
zen-2f6461e3ed7851bc5592b6bc9efdfb0d973fe284.zip
remove use of Ref<> in ZenCacheStore
naming cleanup
Diffstat (limited to 'zenserver/cache/structuredcachestore.cpp')
-rw-r--r--zenserver/cache/structuredcachestore.cpp40
1 files changed, 20 insertions, 20 deletions
diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp
index 3ac319961..1d43e9591 100644
--- a/zenserver/cache/structuredcachestore.cpp
+++ b/zenserver/cache/structuredcachestore.cpp
@@ -2121,8 +2121,8 @@ ZenCacheStore::ZenCacheStore(CasGc& Gc, std::filesystem::path BasePath) : GcStor
for (const std::string& NamespaceName : Namespaces)
{
- Ref<ZenCacheNamespace> Store = new ZenCacheNamespace(Gc, BasePath / fmt::format("{}{}", ZenCacheNamespaceDirPrefix, NamespaceName));
- m_Namespaces[NamespaceName] = Store;
+ m_Namespaces[NamespaceName] =
+ std::make_unique<ZenCacheNamespace>(Gc, BasePath / fmt::format("{}{}", ZenCacheNamespaceDirPrefix, NamespaceName));
}
}
@@ -2134,7 +2134,7 @@ ZenCacheStore::~ZenCacheStore()
bool
ZenCacheStore::Get(std::string_view Namespace, std::string_view Bucket, const IoHash& HashKey, ZenCacheValue& OutValue)
{
- if (Ref<ZenCacheNamespace> Store = GetStore(Namespace); Store)
+ if (ZenCacheNamespace* Store = GetNamespace(Namespace); Store)
{
return Store->Get(Bucket, HashKey, OutValue);
}
@@ -2145,7 +2145,7 @@ ZenCacheStore::Get(std::string_view Namespace, std::string_view Bucket, const Io
void
ZenCacheStore::Put(std::string_view Namespace, std::string_view Bucket, const IoHash& HashKey, const ZenCacheValue& Value)
{
- if (Ref<ZenCacheNamespace> Store = GetStore(Namespace); Store)
+ if (ZenCacheNamespace* Store = GetNamespace(Namespace); Store)
{
return Store->Put(Bucket, HashKey, Value);
}
@@ -2155,7 +2155,7 @@ ZenCacheStore::Put(std::string_view Namespace, std::string_view Bucket, const Io
bool
ZenCacheStore::DropBucket(std::string_view Namespace, std::string_view Bucket)
{
- if (Ref<ZenCacheNamespace> Store = GetStore(Namespace); Store)
+ if (ZenCacheNamespace* Store = GetNamespace(Namespace); Store)
{
return Store->DropBucket(Bucket);
}
@@ -2166,62 +2166,62 @@ ZenCacheStore::DropBucket(std::string_view Namespace, std::string_view Bucket)
void
ZenCacheStore::Flush()
{
- IterateStores([&](const Ref<ZenCacheNamespace>& Store) { Store->Flush(); });
+ IterateNamespaces([&](std::string_view, ZenCacheNamespace& Store) { Store.Flush(); });
}
void
ZenCacheStore::Scrub(ScrubContext& Ctx)
{
- IterateStores([&](const Ref<ZenCacheNamespace>& Store) { Store->Scrub(Ctx); });
+ IterateNamespaces([&](std::string_view, ZenCacheNamespace& Store) { Store.Scrub(Ctx); });
}
-Ref<ZenCacheNamespace>
-ZenCacheStore::GetStore(std::string_view Namespace)
+ZenCacheNamespace*
+ZenCacheStore::GetNamespace(std::string_view Namespace)
{
RwLock::SharedLockScope _(m_NamespacesLock);
if (auto It = m_Namespaces.find(std::string(Namespace)); It != m_Namespaces.end())
{
- return It->second;
+ return It->second.get();
}
return nullptr;
}
void
-ZenCacheStore::IterateStores(const std::function<void(const Ref<ZenCacheNamespace>& Store)>& Callback) const
+ZenCacheStore::IterateNamespaces(const std::function<void(std::string_view Namespace, ZenCacheNamespace& Store)>& Callback) const
{
- std::vector<Ref<ZenCacheNamespace>> Stores;
+ std::vector<std::pair<std::string, ZenCacheNamespace&> > Namespaces;
{
RwLock::SharedLockScope _(m_NamespacesLock);
- Stores.reserve(m_Namespaces.size());
+ Namespaces.reserve(m_Namespaces.size());
for (const auto& Entry : m_Namespaces)
{
- Stores.push_back(Entry.second);
+ Namespaces.push_back({Entry.first, *Entry.second});
}
}
- for (const Ref<ZenCacheNamespace>& Store : Stores)
+ for (auto& Entry : Namespaces)
{
- Callback(Store);
+ Callback(Entry.first, Entry.second);
}
}
void
ZenCacheStore::GatherReferences(GcContext& GcCtx)
{
- IterateStores([&](const Ref<ZenCacheNamespace>& Store) { Store->GatherReferences(GcCtx); });
+ IterateNamespaces([&](std::string_view, ZenCacheNamespace& Store) { Store.GatherReferences(GcCtx); });
}
void
ZenCacheStore::CollectGarbage(GcContext& GcCtx)
{
- IterateStores([&](const Ref<ZenCacheNamespace>& Store) { Store->CollectGarbage(GcCtx); });
+ IterateNamespaces([&](std::string_view, ZenCacheNamespace& Store) { Store.CollectGarbage(GcCtx); });
}
GcStorageSize
ZenCacheStore::StorageSize() const
{
GcStorageSize Size;
- IterateStores([&](const Ref<ZenCacheNamespace>& Store) {
- GcStorageSize StoreSize = Store->StorageSize();
+ IterateNamespaces([&](std::string_view, ZenCacheNamespace& Store) {
+ GcStorageSize StoreSize = Store.StorageSize();
Size.MemorySize += StoreSize.MemorySize;
Size.DiskSize += StoreSize.DiskSize;
});