summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIhor Radchenko <yantar92@gmail.com>2022-06-12 13:32:35 +0800
committerEli Zaretskii <eliz@gnu.org>2022-06-16 10:52:54 +0300
commitd21412df06b99b551e67d39c097d95e8a284de73 (patch)
tree9017d5396dc47b283769d97e0389c92bcd39132a
parent3236dedc2de5975afde877f7460bd012da89a98d (diff)
downloademacs-d21412df06b99b551e67d39c097d95e8a284de73.tar.gz
emacs-d21412df06b99b551e67d39c097d95e8a284de73.tar.bz2
emacs-d21412df06b99b551e67d39c097d95e8a284de73.zip
org-export-resolve-id-link: Pre-cache all the ids in the parse tree
* lisp/org/ox.el (org-export-resolve-id-link): Pre-cache all the ids in the parse tree for faster lookup.
-rw-r--r--lisp/org/ox.el30
1 files changed, 21 insertions, 9 deletions
diff --git a/lisp/org/ox.el b/lisp/org/ox.el
index 4a9387519f5..b431d71193e 100644
--- a/lisp/org/ox.el
+++ b/lisp/org/ox.el
@@ -4393,15 +4393,27 @@ tree or a file name. Assume LINK type is either \"id\" or
\"custom-id\". Throw an error if no match is found."
(let ((id (org-element-property :path link)))
;; First check if id is within the current parse tree.
- (or (org-element-map (plist-get info :parse-tree) 'headline
- (lambda (headline)
- (when (or (equal (org-element-property :ID headline) id)
- (equal (org-element-property :CUSTOM_ID headline) id))
- headline))
- info 'first-match)
- ;; Otherwise, look for external files.
- (cdr (assoc id (plist-get info :id-alist)))
- (signal 'org-link-broken (list id)))))
+ (or (let ((local-ids (or (plist-get info :id-local-cache)
+ (let ((table (make-hash-table :test #'equal)))
+ (org-element-map
+ (plist-get info :parse-tree)
+ 'headline
+ (lambda (headline)
+ (let ((id (org-element-property :ID headline))
+ (custom-id (org-element-property :CUSTOM_ID headline)))
+ (when id
+ (unless (gethash id table)
+ (puthash id headline table)))
+ (when custom-id
+ (unless (gethash custom-id table)
+ (puthash custom-id headline table)))))
+ info)
+ (plist-put info :id-local-cache table)
+ table))))
+ (gethash id local-ids))
+ ;; Otherwise, look for external files.
+ (cdr (assoc id (plist-get info :id-alist)))
+ (signal 'org-link-broken (list id)))))
(defun org-export-resolve-radio-link (link info)
"Return radio-target object referenced as LINK destination.