]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
xh_thread_fp: optimize OR query generation
authorEric Wong <e@80x24.org>
Sun, 23 Feb 2025 13:13:35 +0000 (13:13 +0000)
committerEric Wong <e@80x24.org>
Wed, 26 Feb 2025 02:19:54 +0000 (02:19 +0000)
For Xapian >= 1.4.10 users, using `|=' will reduce allocations.
`|=' still works for Xapian 1.3.2 .. 1.4.9 users, and I'm not
sure if Xapian 1.2.x is relevant anymore, especially for our
new C++-only features.

While operator overloading is often confusing and frustrating to
me when reading someone else's code, the optimization seems worth
it since (AFAIK) there's no other way to get the allocation
reduction.

cf. Olly in xapian-discuss <20250222043050.GA17282@survex.com>

lib/PublicInbox/xh_thread_fp.h

index 27b5cfcb58e842af6cd5f800cd4800de26da8f89..8f0385f14043f0e9f9ec5f049e341478cba892dd 100644 (file)
@@ -17,10 +17,10 @@ static enum exc_iter xpand_col_iter(Xapian::Query *xqry,
        try {
                Xapian::Document doc = i->get_document();
                std::string val = doc.get_value(column);
-               *xqry = Xapian::Query(Xapian::Query::OP_OR, *xqry,
-                               Xapian::Query(
-                                       Xapian::Query::OP_VALUE_RANGE,
-                                       column, val, val));
+               // n.b. Xapian 1.4.10+ optimizes `|=' to reduce allocation.
+               // operator overloading is confusing, yes :<
+               *xqry |= Xapian::Query(Xapian::Query::OP_VALUE_RANGE,
+                                       column, val, val);
        } catch (const Xapian::DatabaseModifiedError &e) {
                cur_srch->db->reopen();
                return ITER_RETRY;