emacs-diffs
[Top][All Lists]
Advanced

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

master 67977ae5974: Eliminate some nested repetitions in regexps


From: Mattias Engdegård
Subject: master 67977ae5974: Eliminate some nested repetitions in regexps
Date: Sun, 29 Oct 2023 12:43:39 -0400 (EDT)

branch: master
commit 67977ae5974e54d34034aa7990cf22dd162c179b
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    Eliminate some nested repetitions in regexps
    
    Nested repetitions such as (A*)* potentially take exponential time but
    can usually be rewritten in a faster and more readable way without
    much trouble.  These were all found by Relint.
    
    * lisp/obsolete/terminal.el (te-parse-program-and-args):
    * lisp/org/org.el (org-make-tags-matcher):
    Apply the transform (A+B*)+ -> A(A|B)*
    
    * lisp/textmodes/fill.el (adaptive-fill-regexp):
    Apply the transform A*(B+A*)* -> (A|B)*
    
    * lisp/progmodes/idlw-shell.el (idlwave-shell-filter):
    Find the last newline or CR in a more direct way.
    
    * lisp/progmodes/vhdl-mode.el (vhdl-port-copy, vhdl-subprog-copy):
    Trim trailing whitespace from a string in a more direct way.
    All-whitespace strings are left unchanged as before.
---
 lisp/obsolete/terminal.el    |  2 +-
 lisp/org/org.el              |  2 +-
 lisp/progmodes/idlw-shell.el |  4 +---
 lisp/progmodes/vhdl-mode.el  | 17 +++++++++--------
 lisp/textmodes/fill.el       |  2 +-
 5 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/lisp/obsolete/terminal.el b/lisp/obsolete/terminal.el
index 4e23fc3c710..31c1ebead14 100644
--- a/lisp/obsolete/terminal.el
+++ b/lisp/obsolete/terminal.el
@@ -1154,7 +1154,7 @@ subprocess started."
 
 
 (defun te-parse-program-and-args (s)
-  (cond ((string-match "\\`\\([-a-zA-Z0-9+=_.@/:]+[ \t]*\\)+\\'" s)
+  (cond ((string-match "\\`[-a-zA-Z0-9+=_.@/:][-a-zA-Z0-9+=_.@/: \t]*\\'" s)
         (let ((l ()) (p 0))
           (while p
             (setq l (cons (if (string-match
diff --git a/lisp/org/org.el b/lisp/org/org.el
index 8b02721a859..49f62d0f43b 100644
--- a/lisp/org/org.el
+++ b/lisp/org/org.el
@@ -11346,7 +11346,7 @@ See also `org-scan-tags'."
   (let ((match0 match)
        (re (concat
             "^&?\\([-+:]\\)?\\({[^}]+}\\|LEVEL\\([<=>]\\{1,2\\}\\)"
-            "\\([0-9]+\\)\\|\\(\\(?:[[:alnum:]_]+\\(?:\\\\-\\)*\\)+\\)"
+            "\\([0-9]+\\)\\|\\([[:alnum:]_]\\(?:[[:alnum:]_]\\|\\\\-\\)*\\)"
             "\\([<>=]\\{1,2\\}\\)"
             "\\({[^}]+}\\|\"[^\"]*\"\\|-?[.0-9]+\\(?:[eE][-+]?[0-9]+\\)?\\)"
             "\\|" org-tag-re "\\)"))
diff --git a/lisp/progmodes/idlw-shell.el b/lisp/progmodes/idlw-shell.el
index e50e1226b43..37c501ae4e2 100644
--- a/lisp/progmodes/idlw-shell.el
+++ b/lisp/progmodes/idlw-shell.el
@@ -1454,9 +1454,7 @@ and then calls `idlwave-shell-send-command' for any 
pending commands."
                         (concat idlwave-shell-accumulation string)))
                    (setq idlwave-shell-accumulation
                          (substring string
-                                    (progn (string-match "\\(.*[\n\r]+\\)*"
-                                                         string)
-                                           (match-end 0)))))
+                                    (string-match "[^\n\r]*\\'" string))))
                (setq idlwave-shell-accumulation
                      (concat idlwave-shell-accumulation string)))
 
diff --git a/lisp/progmodes/vhdl-mode.el b/lisp/progmodes/vhdl-mode.el
index 8d0a10c0918..b55fae3374a 100644
--- a/lisp/progmodes/vhdl-mode.el
+++ b/lisp/progmodes/vhdl-mode.el
@@ -11769,8 +11769,8 @@ reflected in a subsequent paste operation."
                (setq comment (substring type (match-beginning 2)))
                (setq type (substring type 0 (match-beginning 1))))
              ;; strip of trailing group-comment
-             (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
-             (setq type (substring type 0 (match-end 1)))
+              (when (string-match "\\S-\\s-*\\'" type)
+               (setq type (substring type 0 (1+ (match-beginning 0)))))
              ;; parse initialization expression
              (setq init nil)
              (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
@@ -11844,8 +11844,8 @@ reflected in a subsequent paste operation."
                (setq comment (substring type (match-beginning 2)))
                (setq type (substring type 0 (match-beginning 1))))
              ;; strip of trailing group-comment
-             (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
-             (setq type (substring type 0 (match-end 1)))
+              (when (string-match "\\S-\\s-*\\'" type)
+               (setq type (substring type 0 (1+ (match-beginning 0)))))
              (vhdl-forward-syntactic-ws)
              (setq end-of-list (vhdl-parse-string ")" t))
              (vhdl-parse-string "\\s-*;\\s-*")
@@ -12580,8 +12580,8 @@ reflected in a subsequent paste operation."
              (setq comment (substring type (match-beginning 2)))
              (setq type (substring type 0 (match-beginning 1))))
            ;; strip off trailing group-comment
-           (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
-           (setq type (substring type 0 (match-end 1)))
+            (when (string-match "\\S-\\s-*\\'" type)
+             (setq type (substring type 0 (1+ (match-beginning 0)))))
            ;; parse initialization expression
            (setq init nil)
            (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
@@ -12621,8 +12621,9 @@ reflected in a subsequent paste operation."
                (setq return-comment (substring return-type (match-beginning 
2)))
                (setq return-type (substring return-type 0 (match-beginning 
1))))
              ;; strip of trailing group-comment
-             (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
-             (setq return-type (substring return-type 0 (match-end 1)))
+              (when (string-match "\\S-\\s-*\\'" return-type)
+               (setq return-type
+                      (substring return-type 0 (1+ (match-beginning 0)))))
              ;; parse return comment
              (unless return-comment
                (setq return-comment (and (vhdl-parse-string 
"--\\s-*\\([^\n]*\\)" t)
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index 2fde2ff6c4d..4d6c73bfdd6 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -103,7 +103,7 @@ reinserts the fill prefix in each resulting line."
   ;; Added `%' for TeX comments.
   ;; RMS: deleted the code to match `1.' and `(1)'.
   ;; Update mail-mode's paragraph-separate if you change this.
-  (purecopy "[ \t]*\\([-–!|#%;>*·•‣⁃◦]+[ \t]*\\)*")
+  (purecopy "[-–!|#%;>*·•‣⁃◦ \t]*")
   "Regexp to match text at start of line that constitutes indentation.
 If Adaptive Fill mode is enabled, a prefix matching this pattern
 on the first and second lines of a paragraph is used as the



reply via email to

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