server: tweak sexp generation

This commit is contained in:
Dirk-Jan C. Binnema 2023-08-05 11:08:11 +03:00
parent 4945e699c8
commit 01a516f0d3
1 changed files with 15 additions and 11 deletions

View File

@ -174,13 +174,16 @@ append_metadata(std::string& str, const QueryMatch& qmatch)
* A message here consists of a message s-expression with optionally a :docid
* and/or :meta expression added.
*
* Note, for speed reasons, we build is as a _string_, without any further
* parsing.
* We could parse the sexp and use the Sexp APIs to add some things... but...
* it's _much_ faster to directly work on the string representation: remove the
* final ')', add a few items, and add the ')' again.
*/
static std::string
msg_sexp_str(const Message& msg, Store::Id docid, const Option<QueryMatch&> qm)
{
auto sexpstr{msg.document().sexp_str()};
auto&& sexpstr{msg.document().sexp_str()};
if (docid != 0 || qm) {
sexpstr.reserve(sexpstr.size () + (docid == 0 ? 0 : 16) + (qm ? 64 : 0));
// remove the closing ( ... )
@ -192,6 +195,7 @@ msg_sexp_str(const Message& msg, Store::Id docid, const Option<QueryMatch&> qm)
append_metadata(sexpstr, *qm);
sexpstr += ')'; // ... end close it again.
}
return sexpstr;
}