Commit 67977ae5 authored by Mattias Engdegård's avatar Mattias Engdegård
Browse files

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.
parent 7e47d884
Pipeline #26980 failed with stage
in 16 minutes and 57 seconds
......@@ -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
......
......@@ -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 "\\)"))
......
......@@ -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)))
......
......@@ -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)
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment