@@ -4399,15 +4399,27 @@ tree or a file name. Assume LINK type is either \"id\" or
43994399\"custom-id\". Throw an error if no match is found."
44004400 (let ((id (org-element-property :path link)))
44014401 ;; First check if id is within the current parse tree.
4402- (or (org-element-map (plist-get info :parse-tree) 'headline
4403- (lambda (headline)
4404- (when (or (equal (org-element-property :ID headline) id)
4405- (equal (org-element-property :CUSTOM_ID headline) id))
4406- headline))
4407- info 'first-match)
4408- ;; Otherwise, look for external files.
4409- (cdr (assoc id (plist-get info :id-alist)))
4410- (signal 'org-link-broken (list id)))))
4402+ (or (let ((local-ids (or (plist-get info :id-local-cache)
4403+ (let ((table (make-hash-table :test #'equal)))
4404+ (org-element-map
4405+ (plist-get info :parse-tree)
4406+ 'headline
4407+ (lambda (headline)
4408+ (let ((id (org-element-property :ID headline))
4409+ (custom-id (org-element-property :CUSTOM_ID headline)))
4410+ (when id
4411+ (unless (gethash id table)
4412+ (puthash id headline table)))
4413+ (when custom-id
4414+ (unless (gethash custom-id table)
4415+ (puthash custom-id headline table)))))
4416+ info)
4417+ (plist-put info :id-local-cache table)
4418+ table))))
4419+ (gethash id local-ids))
4420+ ;; Otherwise, look for external files.
4421+ (cdr (assoc id (plist-get info :id-alist)))
4422+ (signal 'org-link-broken (list id)))))
44114423
44124424(defun org-export-resolve-radio-link (link info)
44134425 "Return radio-target object referenced as LINK destination.
0 commit comments