GNU bug report logs - #36444
[PATCH] Improved regexp-opt KEEP-ORDER check

Previous Next

Package: emacs;

Reported by: Mattias Engdegård <mattiase <at> acm.org>

Date: Sun, 30 Jun 2019 12:30:02 UTC

Severity: normal

Tags: patch

Done: Mattias Engdegård <mattiase <at> acm.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Mattias Engdegård <mattiase <at> acm.org>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: 36444 <at> debbugs.gnu.org
Subject: bug#36444: [PATCH] Improved regexp-opt KEEP-ORDER check
Date: Thu, 4 Jul 2019 13:52:31 +0200
3 juli 2019 kl. 21.29 skrev Noam Postavsky <npostavs <at> 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 "\\)")))))






This bug report was last modified 6 years and 36 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.