0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

ircd::db: Inline pointer-conditional overloads for cache interface.

This commit is contained in:
Jason Volk 2020-02-19 08:49:33 -08:00
parent 43f5ebe8e3
commit e886e79073
2 changed files with 98 additions and 81 deletions

View file

@ -66,3 +66,100 @@ namespace ircd::db
void clear(rocksdb::Cache &);
void clear(rocksdb::Cache *const &);
}
inline void
ircd::db::clear(rocksdb::Cache *const &cache)
{
if(cache)
return clear(*cache);
}
inline bool
ircd::db::remove(rocksdb::Cache *const &cache,
const string_view &key)
{
return cache?
remove(*cache, key):
false;
}
inline bool
ircd::db::insert(rocksdb::Cache *const &cache,
const string_view &key,
const string_view &value)
{
return cache?
insert(*cache, key, value):
false;
}
inline bool
ircd::db::insert(rocksdb::Cache *const &cache,
const string_view &key,
unique_buffer<const_buffer> &&value)
{
return cache?
insert(*cache, key, std::move(value)):
false;
}
inline void
ircd::db::for_each(const rocksdb::Cache *const &cache,
const cache_closure &closure)
{
if(cache)
for_each(*cache, closure);
}
inline bool
ircd::db::exists(const rocksdb::Cache *const &cache,
const string_view &key)
{
return cache?
exists(*cache, key):
false;
}
inline size_t
ircd::db::pinned(const rocksdb::Cache *const &cache)
{
return cache?
pinned(*cache):
0UL;
}
inline size_t
ircd::db::usage(const rocksdb::Cache *const &cache)
{
return cache?
usage(*cache):
0UL;
}
inline bool
ircd::db::capacity(rocksdb::Cache *const &cache,
const size_t &cap)
{
if(!cache)
return false;
capacity(*cache, cap);
return true;
}
inline size_t
ircd::db::capacity(const rocksdb::Cache *const &cache)
{
return cache?
capacity(*cache):
0UL;
}
inline uint64_t
ircd::db::ticker(const rocksdb::Cache *const &cache,
const uint32_t &ticker_id)
{
return cache?
ticker(*cache, ticker_id):
0UL;
}

View file

@ -7042,26 +7042,12 @@ const
// cache.h
//
void
ircd::db::clear(rocksdb::Cache *const &cache)
{
if(cache)
return clear(*cache);
}
void
ircd::db::clear(rocksdb::Cache &cache)
{
cache.EraseUnRefEntries();
}
bool
ircd::db::remove(rocksdb::Cache *const &cache,
const string_view &key)
{
return cache? remove(*cache, key) : false;
}
bool
ircd::db::remove(rocksdb::Cache &cache,
const string_view &key)
@ -7070,14 +7056,6 @@ ircd::db::remove(rocksdb::Cache &cache,
return true;
}
bool
ircd::db::insert(rocksdb::Cache *const &cache,
const string_view &key,
const string_view &value)
{
return cache? insert(*cache, key, value) : false;
}
bool
ircd::db::insert(rocksdb::Cache &cache,
const string_view &key,
@ -7091,14 +7069,6 @@ ircd::db::insert(rocksdb::Cache &cache,
return insert(cache, key, std::move(buf));
}
bool
ircd::db::insert(rocksdb::Cache *const &cache,
const string_view &key,
unique_buffer<const_buffer> &&value)
{
return cache? insert(*cache, key, std::move(value)) : false;
}
bool
ircd::db::insert(rocksdb::Cache &cache,
const string_view &key,
@ -7130,14 +7100,6 @@ ircd::db::insert(rocksdb::Cache &cache,
return true;
}
void
ircd::db::for_each(const rocksdb::Cache *const &cache,
const cache_closure &closure)
{
if(cache)
for_each(*cache, closure);
}
void
ircd::db::for_each(const rocksdb::Cache &cache,
const cache_closure &closure)
@ -7170,13 +7132,7 @@ ircd::db::for_each(const rocksdb::Cache &cache,
true);
}
bool
ircd::db::exists(const rocksdb::Cache *const &cache,
const string_view &key)
{
return cache? exists(*cache, key) : false;
}
[[gnu::hot]]
bool
ircd::db::exists(const rocksdb::Cache &cache_,
const string_view &key)
@ -7197,41 +7153,18 @@ ircd::db::exists(const rocksdb::Cache &cache_,
return bool(handle);
}
size_t
ircd::db::pinned(const rocksdb::Cache *const &cache)
{
return cache? pinned(*cache) : 0;
}
size_t
ircd::db::pinned(const rocksdb::Cache &cache)
{
return cache.GetPinnedUsage();
}
size_t
ircd::db::usage(const rocksdb::Cache *const &cache)
{
return cache? usage(*cache) : 0;
}
size_t
ircd::db::usage(const rocksdb::Cache &cache)
{
return cache.GetUsage();
}
bool
ircd::db::capacity(rocksdb::Cache *const &cache,
const size_t &cap)
{
if(!cache)
return false;
capacity(*cache, cap);
return true;
}
void
ircd::db::capacity(rocksdb::Cache &cache,
const size_t &cap)
@ -7239,25 +7172,12 @@ ircd::db::capacity(rocksdb::Cache &cache,
cache.SetCapacity(cap);
}
size_t
ircd::db::capacity(const rocksdb::Cache *const &cache)
{
return cache? capacity(*cache): 0;
}
size_t
ircd::db::capacity(const rocksdb::Cache &cache)
{
return cache.GetCapacity();
}
uint64_t
ircd::db::ticker(const rocksdb::Cache *const &cache,
const uint32_t &ticker_id)
{
return cache? ticker(*cache, ticker_id) : 0UL;
}
const uint64_t &
ircd::db::ticker(const rocksdb::Cache &cache,
const uint32_t &ticker_id)