emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: master ea93326: Add `union' and `intersection' to rx (bug#37849)


From: Stefan Monnier
Subject: Re: master ea93326: Add `union' and `intersection' to rx (bug#37849)
Date: Sun, 15 Dec 2019 15:04:29 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

>>> A bit overkill just for matching a set of constant strings, don't you think?
>> I think there's a lot of implicit assumptions here.
>> Yes, there are cases where you may want the "longest match" rule and
>> where `posix-string-match` can be too costly, but the ones I can think
>> of seem to be fairly contrived.
> Perhaps I should have underlined that it is only literal strings that is of
> immediate concern, since that is what regexp-opt is used for. It is not
> a contrived situation to have a set of strings -- keywords, for instance --
> not necessarily anchored by something else at the end.

We need more elements for a realistic scenario. E.g. when the regexp
match fails, `posix-string-match` has the same cost as `string-match`,
so not only you need the end of the regexp not to be anchored to something else
at the end, but you also need all of the below:

- the match should be frequent enough for performance to matter
- the match should almost always succeed
- it needs to matter exactly where the match end
- one of the matched words needs to be a prefix of another
- you can "extract the next word" and look it up in a hash-table instead
  of performing a regexp match

FWIW, I think we can fix this by using a non-backtracking regexp
matcher, but I don't see it as a strong motivation for such a change
(there are good motivations for that, but this one is a pretty weak one
in my book).


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]