Alan Mackenzie avatar Alan Mackenzie committed 8dbdc28

Optimise c-state-safe-place

Comments (0)

Files changed (1)

     (widen)
     (save-excursion
       (let ((c c-state-nonlit-pos-cache)
-	    pos npos lit macro-beg macro-end)
+	    pos npos high-pos lit macro-beg macro-end)
 	;; Trim the cache to take account of buffer changes.
 	(while (and c (> (car c) c-state-nonlit-pos-cache-limit))
 	  (setq c (cdr c)))
 	(setq c-state-nonlit-pos-cache c)
 
 	(while (and c (> (car c) here))
+	  (setq high-pos (car c))
 	  (setq c (cdr c)))
 	(setq pos (or (car c) (point-min)))
 
-	(while
-	    ;; Add an element to `c-state-nonlit-pos-cache' each iteration.
-	    (and
-	     (<= (setq npos (+ pos c-state-nonlit-pos-interval)) here)
-
-	     ;; Test for being in a literal.
-	     (progn
-	       (setq lit (car (cddr (c-state-pp-to-literal pos npos))))
-	       (or (null lit)
-		   (prog1 (<= (cdr lit) here)
-		     (setq npos (cdr lit)))))
-
-	     ;; Test for being in a macro.
-	     (progn
-	       (goto-char npos)
-	       (setq macro-beg
-		     (and (c-beginning-of-macro) (/= (point) npos) (point)))
-	       (when macro-beg
-		 (c-syntactic-end-of-macro)
-		 (or (eobp) (forward-char))
-		 (setq macro-end (point)))
-	       (or (null macro-beg)
-		   (prog1 (<= macro-end here)
-		     (setq npos macro-end)))))
-
-	  (setq pos npos)
-	  (setq c-state-nonlit-pos-cache (cons pos c-state-nonlit-pos-cache)))
+	(unless high-pos
+	  (while
+	      ;; Add an element to `c-state-nonlit-pos-cache' each iteration.
+	      (and
+	       (<= (setq npos (+ pos c-state-nonlit-pos-interval)) here)
+
+	       ;; Test for being in a literal.  If so, go to after it.
+	       (progn
+		 (setq lit (car (cddr (c-state-pp-to-literal pos npos))))
+		 (or (null lit)
+		     (prog1 (<= (cdr lit) here)
+		       (setq npos (cdr lit)))))
+
+	       ;; Test for being in a macro.  If so, go to after it.
+	       (progn
+		 (goto-char npos)
+		 (setq macro-beg
+		       (and (c-beginning-of-macro) (/= (point) npos) (point)))
+		 (when macro-beg
+		   (c-syntactic-end-of-macro)
+		   (or (eobp) (forward-char))
+		   (setq macro-end (point)))
+		 (or (null macro-beg)
+		     (prog1 (<= macro-end here)
+		       (setq npos macro-end)))))
+
+	    (setq pos npos)
+	    (setq c-state-nonlit-pos-cache (cons pos c-state-nonlit-pos-cache))))
 
 	(if (> pos c-state-nonlit-pos-cache-limit)
 	    (setq c-state-nonlit-pos-cache-limit pos))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.