From: Eric Wong Date: Sun, 23 Feb 2025 13:13:35 +0000 (+0000) Subject: xh_thread_fp: optimize OR query generation X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=da87e953fa92de4ecb91e318477e1ee84ed4fe81;p=thirdparty%2Fpublic-inbox.git xh_thread_fp: optimize OR query generation 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> --- diff --git a/lib/PublicInbox/xh_thread_fp.h b/lib/PublicInbox/xh_thread_fp.h index 27b5cfcb5..8f0385f14 100644 --- a/lib/PublicInbox/xh_thread_fp.h +++ b/lib/PublicInbox/xh_thread_fp.h @@ -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;