[Xapian-tickets] [Xapian] #332: Avoid const_cast in matcher/queryoptimiser.cc

Xapian nobody at xapian.org
Wed Sep 7 06:55:57 BST 2016


#332: Avoid const_cast in matcher/queryoptimiser.cc
---------------------+------------------------------
 Reporter:  richard  |             Owner:  richard
     Type:  defect   |            Status:  closed
 Priority:  normal   |         Milestone:  1.1.0
Component:  Matcher  |           Version:  SVN trunk
 Severity:  normal   |        Resolution:  fixed
 Keywords:           |        Blocked By:
 Blocking:           |  Operating System:  All
---------------------+------------------------------

Comment (by olly):

 I noticed `ConstDatabaseWrapper` was missing forwarding for
 `get_doclength_lower_bound()` and `get_doclength_upper_bound()` so that
 the base class default implementations are used, which return much less
 good bounds.  That's probably not important for a `PostingSource`, but
 while looking at this I also noticed that we wrap this and pass it on as
 `const Xapian::Database&` so non-const methods can't actually be called
 anyway!

 The `const_cast` is a bit nasty, but the forwarding class needs updating
 for every method addition/removal/update to `Database::Internal`, and it's
 all too easy to miss the need to do this if there's a fall-back
 implementation (as in the case at the start of this comment).  The
 forwarding also adds a little overhead.  Overall I think the `const_cast`
 is the lesser evil, so I've eliminated `ConstDatabaseWrapper` and added a
 regression test for the doclength bounds in
 [0796637843e90efe7ead9a33c891a089b4da875a].

--
Ticket URL: <https://trac.xapian.org/ticket/332#comment:5>
Xapian <//xapian.org/>
Xapian



More information about the Xapian-tickets mailing list