Browse Source

org-get-buffer-tags: Improve performance

* lisp/org.el (org-get-buffer-tags): Use hash table to accumulate
unique tags only.  The old approach also used hash tables under the
hood of `delete-dups', but required extra memory allocation to store
the full tag list.
Ihor Radchenko 2 years ago
parent
commit
819409baab
1 changed files with 7 additions and 6 deletions
  1. 7 6
      lisp/org.el

+ 7 - 6
lisp/org.el

@@ -11812,12 +11812,13 @@ Inherited tags have the `inherited' text property."
   (if (org-element--cache-active-p)
   (if (org-element--cache-active-p)
       ;; `org-element-cache-map' is about 2x faster compared to regexp
       ;; `org-element-cache-map' is about 2x faster compared to regexp
       ;; search.
       ;; search.
-      (let ((tags (org-element-cache-map
-                   (lambda (el) (org-element-property :tags el)))))
-        (mapcar #'list (mapcar #'substring-no-properties
-                               (delete-dups
-                                (append org-file-tags
-                                        (apply #'append tags))))))
+      (let ((hashed (make-hash-table :test #'equal)))
+        (org-element-cache-map
+         (lambda (el)
+           (dolist (tag (org-element-property :tags el))
+             (puthash (list tag) t hashed))))
+        (dolist (tag org-file-tags) (puthash (list tag) t hashed))
+        (hash-table-keys hashed))
     (org-with-point-at 1
     (org-with-point-at 1
       (let (tags)
       (let (tags)
         (while (re-search-forward org-tag-line-re nil t)
         (while (re-search-forward org-tag-line-re nil t)