|
Currently we don't, but it's pretty easy to get it to use it by calling gen_trie. This should speed up parsing by about 5 - 10% (this is what I saw in a microbenchmark).
When parsing a variant of several structs (std::variant<Struct1, ...>), instead of using a trie or some other smarter method we match each field name and try to figure out which struct to construct. This is what currently generated code looks like. Note how the field name is matched against "struct1", "struct2" and "struct3" even though the string "struct" is common between all three cases.
std::variant<mongo::Struct1, mongo::Struct2, mongo::Struct3> _tmp;
|
|
const BSONType variantType = arrayElement.type();
|
switch (variantType) {
|
case Object:
|
{
|
auto firstElement = arrayElement.Obj().firstElement();
|
if (firstElement.fieldNameStringData() == "struct1") {
|
_tmp = mongo::Struct1::parse(ctxt, arrayElement.Obj());
|
} else if (firstElement.fieldNameStringData() == "struct2") {
|
_tmp = mongo::Struct2::parse(ctxt, arrayElement.Obj());
|
} else if (firstElement.fieldNameStringData() == "struct3") {
|
_tmp = mongo::Struct3::parse(ctxt, arrayElement.Obj());
|
} else {
|
ctxt.throwUnknownField(firstElement.fieldNameStringData());
|
}
|
break;
|
}
|
default:
|
ctxt.throwBadType(arrayElement, std::array<BSONType, 0>{});
|
break;
|
}
|
|