0
0
Fork 0
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:
Jason Volk 2018-09-19 16:35:28 -07:00
parent 1faa7e5fdd
commit 9afac08e40
2 changed files with 31 additions and 24 deletions

View file

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

View file

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