summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2023-01-27 17:21:28 +0100
committerMattias EngdegÄrd <mattiase@acm.org>2023-01-27 17:27:15 +0100
commit4287d56bad5201cf0946526bb0e27c17426bd969 (patch)
tree81c57c54a51a43f7d6eccf8a83b05175e0656551
parent627ac228b2ecdf179f36ea41fd0254c091744e4b (diff)
downloademacs-4287d56bad5201cf0946526bb0e27c17426bd969.tar.gz
Repair hideif regexp problems
* lisp/progmodes/hideif.el (hif-white-regexp, hif-tokenize): Avoid superlinear backtracking behaviour by rewriting regexps to avoid nested repetitions and make positive progress each time. Use lazy matching of the innards of /*...*/ comments to avoid matching too much.
-rw-r--r--lisp/progmodes/hideif.el8
1 files changed, 4 insertions, 4 deletions
diff --git a/lisp/progmodes/hideif.el b/lisp/progmodes/hideif.el
index 4405ce0fe04..836db83c2f3 100644
--- a/lisp/progmodes/hideif.el
+++ b/lisp/progmodes/hideif.el
@@ -555,8 +555,8 @@ that form should be displayed.")
(defconst hif-line-concat "\\\\[ \t]*[\n\r]")
;; If `hif-white-regexp' is modified, `hif-tokenize' might need to be modified
;; accordingly.
-(defconst hif-white-regexp (concat "\\(?:\\(?:[ \t]\\|/\\*.*\\*/\\)*"
- "\\(?:" hif-line-concat "\\)?\\)*"))
+(defconst hif-white-regexp (concat "\\(?:[ \t]\\|/\\*.*?\\*/"
+ "\\|\\(?:" hif-line-concat "\\)\\)*"))
(defconst hif-define-regexp (concat hif-cpp-prefix "\\(define\\|undef\\)"))
(defconst hif-id-regexp (concat "[[:alpha:]_][[:alnum:]_]*"))
(defconst hif-etc-regexp "\\.\\.\\.")
@@ -946,8 +946,8 @@ Assuming we've just performed a `hif-token-regexp' lookup."
(let ((token-list nil)
;; Similar to `hif-white-regexp' but keep the spaces if there are
(white-regexp (concat "\\(?:"
- "\\(?:\\([ \t]+\\)\\|\\(?:/\\*.*\\*/\\)?\\)*"
- "\\(?:" hif-line-concat "\\)?"
+ "\\([ \t]+\\)\\|/\\*.*?\\*/"
+ "\\|\\(?:" hif-line-concat "\\)"
"\\)*"))
token)
(setq hif-simple-token-only t)