org-export-resolve-id-link: Pre-cache all the ids in the parse tree

* lisp/ox.el (org-export-resolve-id-link): Pre-cache all the ids in
the parse tree for faster lookup.
This commit is contained in:
Ihor Radchenko 2022-06-12 13:32:35 +08:00
parent 792cd4b0a6
commit 84c89ea7cb
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 21 additions and 9 deletions

View File

@ -4399,15 +4399,27 @@ tree or a file name. Assume LINK type is either \"id\" or
\"custom-id\". Throw an error if no match is found." \"custom-id\". Throw an error if no match is found."
(let ((id (org-element-property :path link))) (let ((id (org-element-property :path link)))
;; First check if id is within the current parse tree. ;; First check if id is within the current parse tree.
(or (org-element-map (plist-get info :parse-tree) 'headline (or (let ((local-ids (or (plist-get info :id-local-cache)
(lambda (headline) (let ((table (make-hash-table :test #'equal)))
(when (or (equal (org-element-property :ID headline) id) (org-element-map
(equal (org-element-property :CUSTOM_ID headline) id)) (plist-get info :parse-tree)
headline)) 'headline
info 'first-match) (lambda (headline)
;; Otherwise, look for external files. (let ((id (org-element-property :ID headline))
(cdr (assoc id (plist-get info :id-alist))) (custom-id (org-element-property :CUSTOM_ID headline)))
(signal 'org-link-broken (list id))))) (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) (defun org-export-resolve-radio-link (link info)
"Return radio-target object referenced as LINK destination. "Return radio-target object referenced as LINK destination.