Jelajahi Sumber

org-agenda-skip: Improve performance

* lisp/org-agenda.el: Remove unnecessary variable assignment.  Prefer
checking ELEMENT type over regexp match when checking if we are inside
comment.  Postpone let-binding until it is strictly necessary.
Ihor Radchenko 2 tahun lalu
induk
melakukan
3e3588dc75
1 mengubah file dengan 19 tambahan dan 16 penghapusan
  1. 19 16
      lisp/org-agenda.el

+ 19 - 16
lisp/org-agenda.el

@@ -4212,22 +4212,25 @@ Also moves point to the end of the skipped region, so that search can
 continue from there.
 continue from there.
 
 
 Optional argument ELEMENT contains element at point."
 Optional argument ELEMENT contains element at point."
-  (let ((p (line-beginning-position)) to)
-    (when (or
-	   (save-excursion (goto-char p) (looking-at comment-start-skip))
-	   (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
-		(or (and (save-match-data (org-in-archived-heading-p nil element))
-		         (org-end-of-subtree t element))
-		    (and (member org-archive-tag org-file-tags)
-			 (goto-char (point-max)))))
-	   (and org-agenda-skip-comment-trees
-                (org-in-commented-heading-p nil element)
-		(org-end-of-subtree t element))
-	   (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
-			     (org-agenda-skip-eval org-agenda-skip-function)))
-		(goto-char to))
-	   (org-in-src-block-p t element))
-      (throw :skip t))))
+  (when (or
+         (if element
+             (eq (org-element-type element) 'comment)
+	   (save-excursion
+             (goto-char (line-beginning-position))
+             (looking-at comment-start-skip)))
+	 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
+	      (or (and (save-match-data (org-in-archived-heading-p nil element))
+		       (org-end-of-subtree t element))
+		  (and (member org-archive-tag org-file-tags)
+		       (goto-char (point-max)))))
+	 (and org-agenda-skip-comment-trees
+              (org-in-commented-heading-p nil element)
+	      (org-end-of-subtree t element))
+         (let ((to (or (org-agenda-skip-eval org-agenda-skip-function-global)
+		       (org-agenda-skip-eval org-agenda-skip-function))))
+           (and to (goto-char to)))
+	 (org-in-src-block-p t element))
+    (throw :skip t)))
 
 
 (defun org-agenda-skip-eval (form)
 (defun org-agenda-skip-eval (form)
   "If FORM is a function or a list, call (or eval) it and return the result.
   "If FORM is a function or a list, call (or eval) it and return the result.