]> git.eshelyaron.com Git - emacs.git/commitdiff
Eliminate some nested repetitions in regexps
authorMattias Engdegård <mattiase@acm.org>
Thu, 5 Oct 2023 12:06:24 +0000 (14:06 +0200)
committerMattias Engdegård <mattiase@acm.org>
Sun, 29 Oct 2023 16:40:36 +0000 (17:40 +0100)
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
lisp/org/org.el
lisp/progmodes/idlw-shell.el
lisp/progmodes/vhdl-mode.el
lisp/textmodes/fill.el

index 4e23fc3c710107535e0591a0a7089ed23f9bb7b2..31c1ebead147fc8eabf97dd01a23bf2df71a2c94 100644 (file)
@@ -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
index 8b02721a85936910fc2ae528d376c2441098aec9..49f62d0f43b16dc8d88086457d1d7dabf38cbdba 100644 (file)
@@ -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 "\\)"))
index e50e1226b43bb5932fd836e1f4d3c72fe47278ac..37c501ae4e27e5c5de9cf5a8a1b63f19ec096a17 100644 (file)
@@ -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)))
 
index 8d0a10c091893161da163291f8f4a292a7b51877..b55fae3374a0f5842c9adca490e60b20de454230 100644 (file)
@@ -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)
index 2fde2ff6c4d8117d7d102cd9f0069e364f6fe6fb..4d6c73bfdd61c7365b95689129db36296d5fde88 100644 (file)
@@ -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