Simplify the do_filtered_draw
hook
#2988
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a small piece of cleanup that I've been meaning to do for a while.
Originally, the
do_filtered_draw
hook was added as a lightweight way for individual strategies to make filtering more efficient (specificallysampled_from
in #1904), without having to fully override.filter
with a custom strategy.(At the time, no non-trivial strategy had a custom
.filter
implementation, so this was worthwhile.)Over time, a few things changed:
UniqueListStrategy
(Efficient unique collections with elements from a sampled_from #1891)sampled_from
were further specialized toUniqueSampledListStrategy
(Improve performance of unique lists withelements=sampled_from(...)
#2031), bypassing the generic code inUniqueListStrategy
.filter
were added to rewrite simple filters onintegers()
into bounds updates (Rewrite simple filters for boundedintegers()
#2853)All together, these developments mean that the original design of
do_filtered_draw
is now more of a liability, adding confusion for little gain.This PR therefore greatly simplifies the design of
do_filtered_draw
by omitting thefilter_strategy
argument, and changing its contract to simply be “likedo_draw
, but if filtering fails then return a sentinel instead of throwing”.Furthermore, most strategies now no longer have a
do_filtered_draw
method at all. Instead they have a_filter_for_filtered_draw
method, which returns an object (currently alwaysFilteredStrategy
) that implementsdo_filtered_draw
.(Note that
SampledFromStrategy
still has ado_filtered_draw
method, but currently it never actually gets called byUniqueListStrategy
because of theUniqueFilteredListStrategy
specialization. I've left it as-is for now, partly because it would work if needed, and partly to avoid having to merge that code back intoSampledFromStrategy.do_draw
for no real benefit.)