Eli Zaretskii writes: >> Cc: 64735@debbugs.gnu.org >> Date: Tue, 02 Sep 2025 12:23:10 -0400 >> From: Spencer Baugh via "Bug reports for GNU Emacs, >> the Swiss army knife of text editors" >> Dmitry Gutov writes: >> >> > On 20/07/2023 00:16, Spencer Baugh wrote: >> >> In Emacs alone, there are a few things we could do: >> >> - we could mitigate the find bug by optimizing the regexp before we pass >> >> it to find; this should basically remove all the overhead but makes the >> >> find command uglier and harder to edit >> > >> > I like these two approaches. >> >> Much delayed, but the attached patch implements this optimization >> approach. In my testing, it provides a substantial speed-up for rgrep. > > Thanks. > >> +(defcustom grep-find-optimize-matching t > > I'd call this grep-find-use-find-regex, or somesuch. Reasonable, changed to grep-find-use-regex. >> +This affects ignores from `grep-find-ignored-directories' and >> +`grep-find-ignored-files' and the globs passed as FILES to `rgrep'." >> + :type 'boolean) > > The :version tag is missing. Added. >> +If `grep-find-optimize-matching' is non-nil and ARG is a known valid >> +find argument, then instead return a single \"-regex\" or \"-iregex\" >> +argument which matches all of GLOBS." >> + (if-let* ((grep-find-optimize-matching) >> + (known-arg (assoc arg '(("-path" "-regex" 'path) >> + ("-name" "-regex" 'name) >> + ("-ipath" "-iregex" 'path) >> + ("-iname" "-iregex" 'name)))) > > Isn't the -regex/-iregex option a GNU extension? If so, this should > only be used with GNU Find. Oops, yes. Added a check for that. > Also, do we need to use -regextype as well, to make sure the regexp we > produce is interpreted correctly? I think no. The find manual says: -- Option: -regextype name ... If this option is not given, GNU Emacs regular expressions are assumed. And we aren't currently passing -regextype, so we can just continue to not do that.