From: Noam Postavsky <npostavs@gmail.com>
To: "Mattias Engdegård" <mattiase@acm.org>
Cc: 36444@debbugs.gnu.org
Subject: bug#36444: [PATCH] Improved regexp-opt KEEP-ORDER check
Date: Wed, 03 Jul 2019 15:29:33 -0400 [thread overview]
Message-ID: <85v9wiex2a.fsf@gmail.com> (raw)
In-Reply-To: <2CE5D98F-8F07-4E79-9132-FDBA0062D8E2@acm.org> ("Mattias \=\?iso-8859-1\?Q\?Engdeg\=E5rd\=22's\?\= message of "Sun, 30 Jun 2019 14:28:57 +0200")
Mattias Engdegård <mattiase@acm.org> writes:
> + ;; The algorithm will generate a pattern that matches
> + ;; longer strings in the list before shorter. If the
> + ;; list order matters, then no string must come after a
> + ;; proper prefix of that string. To check this, verify
> + ;; that a straight or-pattern matches each string
> + ;; entirely.
> + ((and keep-order
> + (let* ((case-fold-search nil)
> + (alts (mapconcat #'regexp-quote strings "\\|")))
> + (and (save-match-data
You don't actually need this save-match-data, right? Because there is
already one at the top level of the function (which I'm also not sure is
really needed, but probably best not to touch that).
> + (let ((s strings))
> + (while (and s
> + (string-match alts (car s))
> + (= (match-end 0) (length (car s))))
> + (setq s (cdr s)))
> + s))
> + (concat (or open "\\(?:") alts "\\)")))))
IMO, a dolist + catch & throw would be a bit more readable; it took me
some puzzling to realize that the early exit was the "non-optimized"
case.
(and keep-order
(let* ((case-fold-search nil)
(alts (mapconcat #'regexp-quote strings "\\|")))
(and (catch 'has-prefix
(dolist (s strings)
(unless (and (string-match alts s)
(= (match-end 0) (length s)))
(throw 'has-prefix s))))
(concat (or open "\\(?:") alts "\\)"))))
next prev parent reply other threads:[~2019-07-03 19:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-30 12:28 bug#36444: [PATCH] Improved regexp-opt KEEP-ORDER check Mattias Engdegård
2019-07-03 19:29 ` Noam Postavsky [this message]
2019-07-04 11:52 ` Mattias Engdegård
2019-07-04 14:18 ` Noam Postavsky
2019-07-04 15:18 ` Mattias Engdegård
2019-07-04 16:01 ` Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=85v9wiex2a.fsf@gmail.com \
--to=npostavs@gmail.com \
--cc=36444@debbugs.gnu.org \
--cc=mattiase@acm.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).