]> git.eshelyaron.com Git - emacs.git/commitdiff
Omit/rewrite useless regexp repetitions
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 13 Apr 2019 02:43:16 +0000 (19:43 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 13 Apr 2019 02:43:41 +0000 (19:43 -0700)
Problem reported by Mattias Engdegård in:
https://lists.gnu.org/r/emacs-devel/2019-04/msg00527.html
* lisp/align.el (align-rules-list):
* lisp/cedet/srecode/srt-mode.el (srecode-font-lock-keywords):
* lisp/emacs-lisp/copyright.el (copyright-regexp):
* lisp/erc/erc-backend.el (JOIN):
* lisp/erc/erc-goodies.el (erc-unmorse):
* lisp/mail/mail-extr.el (mail-extr-telephone-extension-pattern):
* lisp/net/tramp-adb.el (tramp-adb-prompt):
* lisp/org/org-table.el (org-table-range-regexp):
* lisp/progmodes/idlwave.el (idlwave-where):
* lisp/progmodes/verilog-mode.el (verilog-declaration-re-2-no-macro)
(verilog-declaration-re-2-macro, verilog-delete-auto-buffer)
(verilog-auto-inst-port):
* lisp/url/url-misc.el (url-data):
Omit or rewrite useless repetitions that risk being very slow in
the backtracking regexp engine in Emacs.

lisp/align.el
lisp/cedet/srecode/srt-mode.el
lisp/emacs-lisp/copyright.el
lisp/erc/erc-backend.el
lisp/erc/erc-goodies.el
lisp/mail/mail-extr.el
lisp/net/tramp-adb.el
lisp/org/org-table.el
lisp/progmodes/idlwave.el
lisp/progmodes/verilog-mode.el
lisp/url/url-misc.el

index fd88d0eda42cf57792d3d43c280c49d10cca343e..443237b451bf9c15c8448ff3bd2df74ef56f37a6 100644 (file)
@@ -411,7 +411,7 @@ The possible settings for `align-region-separate' are:
     (c-variable-declaration
      (regexp   . ,(concat "[*&0-9A-Za-z_]>?[&*]*\\(\\s-+[*&]*\\)"
                          "[A-Za-z_][0-9A-Za-z:_]*\\s-*\\(\\()\\|"
-                         "=[^=\n].*\\|(.*)\\|\\(\\[.*\\]\\)*\\)?"
+                         "=[^=\n].*\\|(.*)\\|\\(\\[.*\\]\\)*\\)"
                          "\\s-*[;,]\\|)\\s-*$\\)"))
      (group    . 1)
      (modes    . align-c++-modes)
index 2ad7ffcdb87a05ef9a3982b2dddd7eebb53bba76..6bf2d51ab41ccc0e0449bb9774d900bfff3b113c 100644 (file)
@@ -64,7 +64,7 @@
 (defvar srecode-font-lock-keywords
   '(
     ;; Template
-    ("^\\(template\\)\\s-+\\(\\w*\\)\\(\\( \\(:\\w+\\)\\|\\)+\\)$"
+    ("^\\(template\\)\\s-+\\(\\w*\\)\\(\\( \\(:\\w+\\)\\)*\\)$"
      (1 font-lock-keyword-face)
      (2 font-lock-function-name-face)
      (3 font-lock-builtin-face ))
index 2726bbc1f3f80c8af288ee7153b6229691344ce2..be335838e33310746581fa1a6c57325a027b4d27 100644 (file)
@@ -52,7 +52,7 @@ This is useful for ChangeLogs."
 (defcustom copyright-regexp
  "\\(©\\|@copyright{}\\|[Cc]opyright\\s *:?\\s *\\(?:(C)\\)?\
 \\|[Cc]opyright\\s *:?\\s *©\\)\
-\\s *\\(?:[^0-9\n]*\\s *\\)?\
+\\s *[^0-9\n]*\\s *\
 \\([1-9]\\([-0-9, ';/*%#\n\t]\\|\\s<\\|\\s>\\)*[0-9]+\\)"
   "What your copyright notice looks like.
 The second \\( \\) construct must match the years."
index 2854cde19cc2ff233b068cd8267ee3b6f68ec481..210830a2b496735f135f0ffb8a72112d5013a322 100644 (file)
@@ -1285,7 +1285,7 @@ add things to `%s' instead."
     (pcase-let ((`(,nick ,login ,host)
                  (erc-parse-user (erc-response.sender parsed))))
       ;; strip the stupid combined JOIN facility (IRC 2.9)
-      (if (string-match "^\\(.*\\)?\^g.*$" chnl)
+      (if (string-match "^\\(.*\\)\^g.*$" chnl)
           (setq chnl (match-string 1 chnl)))
       (save-excursion
         (let* ((str (cond
index 117b6783b8d201b409e0bece5973148842284c1a..884c594b9ed718421b93a95fe276728e179befc1 100644 (file)
@@ -548,7 +548,7 @@ channel that has weird people talking in morse to each other.
 
 See also `unmorse-region'."
   (goto-char (point-min))
-  (when (re-search-forward "[.-]+\\([.-]*/? *\\)+[.-]+/?" nil t)
+  (when (re-search-forward "[.-]+[./ -]*[.-]/?" nil t)
     (save-restriction
       (narrow-to-region (match-beginning 0) (match-end 0))
       ;; Turn " / " into "  "
index cb57d8ea0168decf949376771538e47362df771b..a0b9688650734b594ee08b2a7affb752fb73ba77 100644 (file)
@@ -383,7 +383,7 @@ by translating things like \"foo!bar!baz@host\" into \"baz@bar.UUCP\"."
 ;; Matches telephone extensions.
 (defconst mail-extr-telephone-extension-pattern
   (purecopy
-   "\\(\\([Ee]xt\\|\\|[Tt]ph\\|[Tt]el\\|[Xx]\\).?\\)? *\\+?[0-9][- 0-9]+"))
+   "\\(\\([Ee]xt\\|[Tt]ph\\|[Tt]el\\|[Xx]\\).?\\)? *\\+?[0-9][- 0-9]+"))
 
 ;; Matches ham radio call signs.
 ;; Help from: Mat Maessen N2NJZ <maessm@rpi.edu>, Mark Feit
index db9acbfc631cf6899ccd65543d793805beedac28..f3aa55f16f52a2e8ed46b4c1bb05cff40bc2646b 100644 (file)
@@ -53,7 +53,7 @@ It is used for TCP/IP devices."
   "When this method name is used, forward all calls to Android Debug Bridge.")
 
 (defcustom tramp-adb-prompt
-  "^\\(?:[[:digit:]]*|?\\)?\\(?:[[:alnum:]\e;[]*@?[[:alnum:]]*[^#\\$]*\\)?[#\\$][[:space:]]"
+  "^[[:digit:]]*|?\\(?:[[:alnum:]\e;[]*@?[[:alnum:]]*[^#\\$]*\\)?[#\\$][[:space:]]"
   "Regexp used as prompt in almquist shell."
   :type 'string
   :version "24.4"
index b6e864fc9c97743737adcf4e0f92fff378cfbbdc..147527da1d39be3bf52c8df3e1671740ac00b4ef 100644 (file)
@@ -484,8 +484,8 @@ Line numbers are counted from the beginning of the table.  This
 variable is initialized with `org-table-analyze'.")
 
 (defconst org-table-range-regexp
-  "@\\([-+]?I*[-+]?[0-9]*\\)?\\(\\$[-+]?[0-9]+\\)?\\(\\.\\.@?\\([-+]?I*[-+]?[0-9]*\\)?\\(\\$[-+]?[0-9]+\\)?\\)?"
-  ;;   1                        2                    3          4                        5
+  "@\\([-+]?I*[-+]?[0-9]*\\)\\(\\$[-+]?[0-9]+\\)?\\(\\.\\.@?\\([-+]?I*[-+]?[0-9]*\\)\\(\\$[-+]?[0-9]+\\)?\\)?"
+  ;;   1                       2                    3          4                       5
   "Regular expression for matching ranges in formulas.")
 
 (defconst org-table-range-regexp2
index bded09d5038f938396c04ee7c2ece2a9c4a3d7ba..6f56ce052a02d29d24e2c4bdcf9dd3017ca1d1c9 100644 (file)
@@ -6454,10 +6454,10 @@ ARROW:  Location of the arrow"
      ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
                    match-string)
       nil)
-     ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
+     ((string-match "OBJ_NEW([ \t]*['\"][a-zA-Z0-9$_]*\\'"
                    match-string)
       (setq cw 'class))
-     ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
+     ((string-match "\\<inherits\\s-+[a-zA-Z0-9$_]*\\'"
                    match-string)
       (setq cw 'class))
      ((and func
index 9226291ffbbdcef63d951eff91955dd2508eb25e..e75e5845ef360bfbb54088534d726d482afba2ed 100644 (file)
@@ -2761,12 +2761,12 @@ find the errors."
 (defconst verilog-declaration-re-2-no-macro
   (concat "\\s-*" verilog-declaration-re
          "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
-         "\\)?"))
+         "\\)"))
 (defconst verilog-declaration-re-2-macro
   (concat "\\s-*" verilog-declaration-re
          "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
          "\\|\\(" verilog-macroexp-re "\\)"
-         "\\)?"))
+         "\\)"))
 (defconst verilog-declaration-re-1-macro
   (concat "^" verilog-declaration-re-2-macro))
 
@@ -10810,7 +10810,7 @@ Intended for internal use inside a `verilog-save-font-no-change-functions' block
                              'verilog-delete-auto-star-all)
   ;; Remove template comments ... anywhere in case was pasted after AUTOINST removed
   (goto-char (point-min))
-  (while (re-search-forward "\\s-*// \\(Templated\\|Implicit \\.\\*\\)\\([ \tLT0-9]*\\| LHS: .*\\)?$" nil t)
+  (while (re-search-forward "\\s-*// \\(Templated\\|Implicit \\.\\*\\)\\([ \tLT0-9]*\\| LHS: .*\\)$" nil t)
     (replace-match ""))
 
   ;; Final customize
@@ -11412,7 +11412,7 @@ If PAR-VALUES replace final strings with these parameter values."
     (when tpl-ass
       ;; Evaluate @"(lispcode)"
       (when (string-match "@\".*[^\\]\"" tpl-net)
-       (while (string-match "@\"\\(\\([^\\\"]*\\(\\\\.\\)*\\)*\\)\"" tpl-net)
+       (while (string-match "@\"\\(\\([^\\\"]\\|\\\\.\\)*\\)\"" tpl-net)
          (setq tpl-net
                (concat
                 (substring tpl-net 0 (match-beginning 0))
index 4969cba66889b55df9967d7ecacfe6c25b7283da..aa44ea78a2292fedd857792d7381fe9404e83dd7 100644 (file)
@@ -88,7 +88,7 @@
        (encoding "8bit")
        (data nil))
     (save-excursion
-      (if (not (string-match "\\([^,]*\\)?," desc))
+      (if (not (string-match "\\([^,]*\\)," desc))
          (error "Malformed data URL: %s" desc)
        (setq mediatype (match-string 1 desc)
              data (url-unhex-string (substring desc (match-end 0))))