Skip to content

Commit c77692e

Browse files
yantar92kyleam
authored andcommitted
Backport commit f94e93a6e from Emacs
* lisp/oc.el (org-cite-list-citations): Avoid quadratic complexity. Pre-calculate list of all footnote definitions and cache the footnote label search hits. Do not make `org-element-map' accumulate unused result. org-cite-list-citations: Cache footnote-definition searches f94e93a6eec92d834a6b545d8d4b68280b0993b0 Ihor Radchenko Thu Jun 16 10:55:05 2022 +0300 [ km: This ported commit comes from main's b061e7b. I'm applying it here too for bookkeeping/traceability purposes. ]
1 parent 0da6c49 commit c77692e

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

lisp/oc.el

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,8 @@ INFO is the export communication channel, as a property list."
808808
(or (plist-get info :citations)
809809
(letrec ((cites nil)
810810
(tree (plist-get info :parse-tree))
811+
(definition-cache (make-hash-table :test #'equal))
812+
(definition-list nil)
811813
(find-definition
812814
;; Find definition for standard reference LABEL. At
813815
;; this point, it is impossible to rely on
@@ -816,11 +818,21 @@ INFO is the export communication channel, as a property list."
816818
;; un-processed citation objects. So we use
817819
;; a simplified version of the function above.
818820
(lambda (label)
819-
(org-element-map tree 'footnote-definition
820-
(lambda (d)
821-
(and (equal label (org-element-property :label d))
822-
(or (org-element-contents d) "")))
823-
info t)))
821+
(or (gethash label definition-cache)
822+
(org-element-map
823+
(or definition-list
824+
(setq definition-list
825+
(org-element-map
826+
tree
827+
'footnote-definition
828+
#'identity info)))
829+
'footnote-definition
830+
(lambda (d)
831+
(and (equal label (org-element-property :label d))
832+
(puthash label
833+
(or (org-element-contents d) "")
834+
definition-cache)))
835+
info t))))
824836
(search-cites
825837
(lambda (data)
826838
(org-element-map data '(citation footnote-reference)
@@ -834,7 +846,8 @@ INFO is the export communication channel, as a property list."
834846
(_
835847
(let ((label (org-element-property :label datum)))
836848
(funcall search-cites
837-
(funcall find-definition label))))))
849+
(funcall find-definition label)))))
850+
nil)
838851
info nil 'footnote-definition t))))
839852
(funcall search-cites tree)
840853
(let ((result (nreverse cites)))

0 commit comments

Comments
 (0)