From: "Mattias Engdegård" <mattiase@acm.org>
To: Noam Postavsky <npostavs@gmail.com>
Cc: 36444@debbugs.gnu.org
Subject: bug#36444: [PATCH] Improved regexp-opt KEEP-ORDER check
Date: Thu, 4 Jul 2019 13:52:31 +0200 [thread overview]
Message-ID: <74D2BB46-AE27-4F7B-8E76-E12527834B53@acm.org> (raw)
In-Reply-To: <85v9wiex2a.fsf@gmail.com>
3 juli 2019 kl. 21.29 skrev Noam Postavsky <npostavs@gmail.com>:
>
> 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).
Thank you! I don't know how I missed the existing save-match-data. Removed.
> 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 "\\)"))))
Not too fond of that either, really; catch/throw somehow seems more heavyweight than warranted by the situation.
Initially I used cl-every, but ran into the usual bootstrap problems.
Here are two alternatives:
(1) Same as before, but with a comment about what tripped you up:
> (and (let ((s strings))
> (while (and s
> (string-match alts (car s))
> (= (match-end 0) (length (car s))))
> (setq s (cdr s)))
> ;; If we exited early, we found evidence that
> ;; regexp-opt-group cannot be used.
> s)
> (concat (or open "\\(?:") alts "\\)")))))
(2) Using cl-loop:
> (and (not (cl-loop
> for s in strings
> always (and (string-match alts s)
> (= (match-end 0) (length s)))))
> (concat (or open "\\(?:") alts "\\)")))))
next prev parent reply other threads:[~2019-07-04 11:52 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
2019-07-04 11:52 ` Mattias Engdegård [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=74D2BB46-AE27-4F7B-8E76-E12527834B53@acm.org \
--to=mattiase@acm.org \
--cc=36444@debbugs.gnu.org \
--cc=npostavs@gmail.com \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.