aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2011-01-29 01:08:24 -0500
committerStefan Monnier2011-01-29 01:08:24 -0500
commite52f87a1c0ac9e6f04c1047d2b4828744e83f7ba (patch)
treedea7c5b7b8ee65198ec2ef9f2f8ce442a28b8f97
parent659114fdba7d5ea14541cdc713c7f9745eb93c46 (diff)
downloademacs-e52f87a1c0ac9e6f04c1047d2b4828744e83f7ba.tar.gz
emacs-e52f87a1c0ac9e6f04c1047d2b4828744e83f7ba.zip
* lisp/progmodes/compile.el: Avoid an N² behavior in grep.
(compilation--previous-directory): New fun. (compilation--previous-directory-cache): New var. (compilation--remove-properties): Flush it. (compilation-directory-properties, compilation-error-properties): Use the new fun to speed up looking for the current directory.
-rw-r--r--lisp/ChangeLog13
-rw-r--r--lisp/progmodes/compile.el46
2 files changed, 54 insertions, 5 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 41242360c60..1b833abe3cf 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,12 @@
12011-01-29 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * progmodes/compile.el: Avoid an N² behavior in grep.
4 (compilation--previous-directory): New fun.
5 (compilation--previous-directory-cache): New var.
6 (compilation--remove-properties): Flush it.
7 (compilation-directory-properties, compilation-error-properties):
8 Use the new fun to speed up looking for the current directory.
9
12011-01-29 Chong Yidong <cyd@stupidchicken.com> 102011-01-29 Chong Yidong <cyd@stupidchicken.com>
2 11
3 * vc/vc-hg.el (vc-hg-history): New var. 12 * vc/vc-hg.el (vc-hg-history): New var.
@@ -18,8 +27,8 @@
18 * vc/vc-bzr.el (vc-bzr-async-command): Convert into a wrapper for 27 * vc/vc-bzr.el (vc-bzr-async-command): Convert into a wrapper for
19 vc-do-async-command. 28 vc-do-async-command.
20 29
21 * vc/vc-bzr.el (vc-bzr-pull, vc-bzr-merge-branch): Callers 30 * vc/vc-bzr.el (vc-bzr-pull, vc-bzr-merge-branch):
22 changed. 31 Callers changed.
23 32
242011-01-28 Leo <sdl.web@gmail.com> 332011-01-28 Leo <sdl.web@gmail.com>
25 34
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index cbbaa4dc68a..5bb3bf227f2 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -834,6 +834,39 @@ from a different message."
834 (:conc-name compilation--message->)) 834 (:conc-name compilation--message->))
835 loc type end-loc) 835 loc type end-loc)
836 836
837(defvar compilation--previous-directory-cache nil)
838(make-variable-buffer-local 'compilation--previous-directory-cache)
839(defun compilation--previous-directory (pos)
840 "Like (previous-single-property-change POS 'compilation-directory), but faster."
841 ;; This avoids an N² behavior when there's no/few compilation-directory
842 ;; entries, in which case each call to previous-single-property-change
843 ;; ends up having to walk very far back to find the last change.
844 (let* ((cache (and compilation--previous-directory-cache
845 (<= (car compilation--previous-directory-cache) pos)
846 (car compilation--previous-directory-cache)))
847 (prev
848 (previous-single-property-change
849 pos 'compilation-directory nil cache)))
850 (cond
851 ((null cache)
852 (setq compilation--previous-directory-cache
853 (cons (copy-marker pos) (copy-marker prev)))
854 prev)
855 ((eq prev cache)
856 (if cache
857 (set-marker (car compilation--previous-directory-cache) pos)
858 (setq compilation--previous-directory-cache
859 (cons (copy-marker pos) nil)))
860 (cdr compilation--previous-directory-cache))
861 (t
862 (if cache
863 (progn
864 (set-marker (car compilation--previous-directory-cache) pos)
865 (setcdr compilation--previous-directory-cache (copy-marker prev)))
866 (setq compilation--previous-directory-cache
867 (cons (copy-marker pos) (copy-marker prev))))
868 prev))))
869
837;; Internal function for calculating the text properties of a directory 870;; Internal function for calculating the text properties of a directory
838;; change message. The compilation-directory property is important, because it 871;; change message. The compilation-directory property is important, because it
839;; is the stack of nested enter-messages. Relative filenames on the following 872;; is the stack of nested enter-messages. Relative filenames on the following
@@ -841,7 +874,7 @@ from a different message."
841(defun compilation-directory-properties (idx leave) 874(defun compilation-directory-properties (idx leave)
842 (if leave (setq leave (match-end leave))) 875 (if leave (setq leave (match-end leave)))
843 ;; find previous stack, and push onto it, or if `leave' pop it 876 ;; find previous stack, and push onto it, or if `leave' pop it
844 (let ((dir (previous-single-property-change (point) 'compilation-directory))) 877 (let ((dir (compilation--previous-directory (point))))
845 (setq dir (if dir (or (get-text-property (1- dir) 'compilation-directory) 878 (setq dir (if dir (or (get-text-property (1- dir) 'compilation-directory)
846 (get-text-property dir 'compilation-directory)))) 879 (get-text-property dir 'compilation-directory))))
847 `(font-lock-face ,(if leave 880 `(font-lock-face ,(if leave
@@ -900,8 +933,7 @@ from a different message."
900 (match-string-no-properties file)))) 933 (match-string-no-properties file))))
901 (let ((dir 934 (let ((dir
902 (unless (file-name-absolute-p file) 935 (unless (file-name-absolute-p file)
903 (let ((pos (previous-single-property-change 936 (let ((pos (compilation--previous-directory (point))))
904 (point) 'compilation-directory)))
905 (when pos 937 (when pos
906 (or (get-text-property (1- pos) 'compilation-directory) 938 (or (get-text-property (1- pos) 'compilation-directory)
907 (get-text-property pos 'compilation-directory))))))) 939 (get-text-property pos 'compilation-directory)))))))
@@ -1064,6 +1096,14 @@ FMTS is a list of format specs for transforming the file name.
1064 1096
1065(defun compilation--remove-properties (&optional start end) 1097(defun compilation--remove-properties (&optional start end)
1066 (with-silent-modifications 1098 (with-silent-modifications
1099 (cond
1100 ((or (not compilation--previous-directory-cache)
1101 (<= (car compilation--previous-directory-cache) start)))
1102 ((or (not (cdr compilation--previous-directory-cache))
1103 (<= (cdr compilation--previous-directory-cache) start))
1104 (set-marker (car compilation--previous-directory-cache) start))
1105 (t (setq compilation--previous-directory-cache nil)))
1106
1067 ;; When compile.el used font-lock directly, we could just remove all 1107 ;; When compile.el used font-lock directly, we could just remove all
1068 ;; our text-properties in one go, but now that we manually place 1108 ;; our text-properties in one go, but now that we manually place
1069 ;; font-lock-face, we have to be careful to only remove the font-lock-face 1109 ;; font-lock-face, we have to be careful to only remove the font-lock-face