Browse Source

org-agenda-prepare-buffers: Avoid quadratic complexity when merging tags

* lisp/org.el (org-agenda-prepare-buffers): Use the shortest list as
the first argument in `org--tag-add-to-alist'.

`org--tag-add-to-alist' is looping over the first argument.  When we
use the accumulated tags as the first argument, each buffer tag will
need to be looped over N_buffers/2 times on average, creating
quadratic complexity.  Avoid this.

Reported in https://orgmode.org/list/62f66552.050a0220.ed346.ac05SMTPIN_ADDED_BROKEN@mx.google.com
Ihor Radchenko 3 years ago
parent
commit
6ad65f3332
1 changed files with 2 additions and 2 deletions
  1. 2 2
      lisp/org.el

+ 2 - 2
lisp/org.el

@@ -15196,8 +15196,8 @@ When a buffer is unmodified, it is just killed.  When modified, it is saved
 		 (append org-todo-keyword-alist-for-agenda org-todo-key-alist))
 	   (setq org-tag-alist-for-agenda
 		 (org--tag-add-to-alist
-		  org-tag-alist-for-agenda
-		  org-current-tag-alist))
+		  org-current-tag-alist
+                  org-tag-alist-for-agenda))
 	   ;; Merge current file's tag groups into global
 	   ;; `org-tag-groups-alist-for-agenda'.
 	   (when org-group-tags