Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix long line perf of compilation-shell-minor-mode #24

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion lisp/progmodes/compile.el
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ to `compilation-error-regexp-alist' if RULES is nil."
(error "HYPERLINK should be an integer: %s" (nth 5 item)))

(goto-char start)
(while (re-search-forward pat end t)
(while (compilation--re-search-forward-limited pat end 1024)
(when (setq props (compilation-error-properties
file line end-line col end-col
(or type 2) fmt rule))
Expand Down Expand Up @@ -1597,6 +1597,28 @@ to `compilation-error-regexp-alist' if RULES is nil."
(match-beginning mn) (match-end mn)
'font-lock-face (cadr props)))))))))

(defun compilation--re-search-forward-limited (regexp bound n)
"Like 're-search-forward limited to the first N chars per line.
This avoids Emacs performance degradation on scanning excessively
long lines of text. It is reasonable when scanning for compiler
warnings to expect to find them early on each line. REGEXP and
BOUND are as in 're-search-forward."
(let ((inhibit-field-text-motion t)
(found nil)
(orig-point (point)))
(while (and (null found)
(< (point) bound)
(not (eobp)))
(setq found (re-search-forward regexp
(max (point)
(min bound (+ (point-at-bol) n)))
t))
(when (null found)
(forward-line 1)))
(when (null found)
(goto-char orig-point))
found))

(defvar-local compilation--parsed -1)

(defun compilation--ensure-parse (limit)
Expand Down