mirror of
https://github.com/matrix-construct/construct
synced 2024-09-30 04:38:52 +02:00
ircd::db: Simplify compaction callback argument requirements w/ struct.
This commit is contained in:
parent
1faa7e5fdd
commit
9afac08e40
2 changed files with 31 additions and 24 deletions
|
@ -25,12 +25,21 @@ namespace ircd::db
|
|||
///
|
||||
struct ircd::db::compactor
|
||||
{
|
||||
using prototype = db::op (const int &level,
|
||||
const string_view &key,
|
||||
const string_view &val,
|
||||
std::string *const replace,
|
||||
std::string *const skip_until);
|
||||
struct args;
|
||||
using proto = db::op (const args &);
|
||||
using callback = std::function<proto>;
|
||||
|
||||
std::function<prototype> value;
|
||||
std::function<prototype> merge;
|
||||
callback value;
|
||||
callback merge;
|
||||
};
|
||||
|
||||
struct ircd::db::compactor::args
|
||||
{
|
||||
const int &level;
|
||||
|
||||
const string_view key;
|
||||
const string_view val;
|
||||
|
||||
std::string *const &replace;
|
||||
std::string *const &skip_until;
|
||||
};
|
||||
|
|
32
ircd/db.cc
32
ircd/db.cc
|
@ -2436,28 +2436,26 @@ const
|
|||
};
|
||||
#endif
|
||||
|
||||
db::op ret
|
||||
const db::compactor::callback &callback
|
||||
{
|
||||
db::op::GET
|
||||
type == ValueType::kValue && user.value?
|
||||
user.value:
|
||||
|
||||
type == ValueType::kMergeOperand && user.merge?
|
||||
user.merge:
|
||||
|
||||
compactor::callback{}
|
||||
};
|
||||
|
||||
switch(type)
|
||||
if(!callback)
|
||||
return Decision::kKeep;
|
||||
|
||||
const compactor::args args
|
||||
{
|
||||
case ValueType::kValue:
|
||||
if(user.value)
|
||||
ret = user.value(level, slice(key), slice(oldval), newval, skip);
|
||||
break;
|
||||
level, slice(key), slice(oldval), newval, skip
|
||||
};
|
||||
|
||||
case ValueType::kMergeOperand:
|
||||
if(user.merge)
|
||||
ret = user.merge(level, slice(key), slice(oldval), newval, skip);
|
||||
break;
|
||||
|
||||
case ValueType::kBlobIndex:
|
||||
break;
|
||||
}
|
||||
|
||||
switch(ret)
|
||||
switch(callback(args))
|
||||
{
|
||||
default:
|
||||
case db::op::GET: return Decision::kKeep;
|
||||
|
|
Loading…
Reference in a new issue