rust-lang/regex

Allow changing a `DFA`'s prefilter after it's already been created

ideka opened this issue · 1 comments

ideka commented

I already added it to my fork but I guess I'd rather discuss it before submitting a PR.

In my use case prefilters are simple and speed up a search by an order of magnitude, but I'm serializing and deserializing DFA's with ::from_bytes, which doesn't preserve prefilters. For this reason I save the prefilter separately and need this function to readd it when deserializing, after the DFA has been built with ::from_bytes.

If changing a DFA at all after it's been built is really undesirable (is it?), another alternative would be to have ::from_bytes_with_prefilter function variants which would serve the same purpose and cover the only thing (as far as I know) that would otherwise be lost in DFA (de)serialization.

Yeah, I wish serialization would just handle prefilters automatically, but sadly that is a huge pile of work with far-reaching consequences.

I'm okay with a method that mutates a DFA in place to add a prefilter. This seems simplest to me since otherwise you'd need multiple constructors that add a prefilter (one for checked and one for unchecked, for example).