[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 5b3d4e7bf0 1/9: org-export-get-footnote-definition: Pre-cache ref
From: |
Eli Zaretskii |
Subject: |
master 5b3d4e7bf0 1/9: org-export-get-footnote-definition: Pre-cache references in parse tree |
Date: |
Thu, 16 Jun 2022 04:09:41 -0400 (EDT) |
branch: master
commit 5b3d4e7bf0b6a1eb576e1c6e6592028e3589f792
Author: Ihor Radchenko <yantar92@gmail.com>
Commit: Eli Zaretskii <eliz@gnu.org>
org-export-get-footnote-definition: Pre-cache references in parse tree
* lisp/org/ox.el (org-export-get-footnote-definition): Pre-process parse
tree once to filter out all non-footnote elements. This speeds up
subsequent footnote definition searches.
---
lisp/org/ox.el | 39 ++++++++++++++++++++++-----------------
1 file changed, 22 insertions(+), 17 deletions(-)
diff --git a/lisp/org/ox.el b/lisp/org/ox.el
index 2a3edaa500..7f90dc36f7 100644
--- a/lisp/org/ox.el
+++ b/lisp/org/ox.el
@@ -3748,28 +3748,33 @@ definition can be found, raise an error."
(if (not label) (org-element-contents footnote-reference)
(let ((cache (or (plist-get info :footnote-definition-cache)
(let ((hash (make-hash-table :test #'equal)))
+ ;; Cache all the footnotes in document for
+ ;; later search.
+ (org-element-map (plist-get info :parse-tree)
+ '(footnote-definition footnote-reference)
+ (lambda (f)
+ ;; Skip any standard footnote reference
+ ;; since those cannot contain a
+ ;; definition.
+ (unless (eq (org-element-property :type f)
'standard)
+ (puthash
+ (cons :element (org-element-property :label f))
+ f
+ hash)))
+ info)
(plist-put info :footnote-definition-cache hash)
hash))))
(or
(gethash label cache)
(puthash label
- (org-element-map (plist-get info :parse-tree)
- '(footnote-definition footnote-reference)
- (lambda (f)
- (cond
- ;; Skip any footnote with a different label.
- ;; Also skip any standard footnote reference
- ;; with the same label since those cannot
- ;; contain a definition.
- ((not (equal (org-element-property :label f) label)) nil)
- ((eq (org-element-property :type f) 'standard) nil)
- ((org-element-contents f))
- ;; Even if the contents are empty, we can not
- ;; return nil since that would eventually raise
- ;; the error. Instead, return the equivalent
- ;; empty string.
- (t "")))
- info t)
+ (let ((hashed (gethash (cons :element label) cache)))
+ (when hashed
+ (or (org-element-contents hashed)
+ ;; Even if the contents are empty, we can not
+ ;; return nil since that would eventually raise
+ ;; the error. Instead, return the equivalent
+ ;; empty string.
+ "")))
cache)
(error "Definition not found for footnote %s" label))))))
- master updated (fdd4dc6bdf -> 217c41c7b0), Eli Zaretskii, 2022/06/16
- master d21412df06 3/9: org-export-resolve-id-link: Pre-cache all the ids in the parse tree, Eli Zaretskii, 2022/06/16
- master 5b3d4e7bf0 1/9: org-export-get-footnote-definition: Pre-cache references in parse tree,
Eli Zaretskii <=
- master 3236dedc2d 2/9: org-export-resolve-fuzyy-link: Pre-cache all possible search cells, Eli Zaretskii, 2022/06/16
- master 217c41c7b0 9/9: Merge branch 'master' of git.savannah.gnu.org:/srv/git/emacs, Eli Zaretskii, 2022/06/16
- master f94e93a6ee 7/9: org-cite-list-citations: Cache footnote-definition searches, Eli Zaretskii, 2022/06/16
- master 0f7ceb4803 4/9: org-export-as: Do not update buffer settings when not modified, Eli Zaretskii, 2022/06/16
- master 979308b4ca 5/9: org-export-data: Concatenate strings in temporary buffer for performance, Eli Zaretskii, 2022/06/16
- master 4f37a3b299 6/9: org-element-map: Avoid repetitive `plist-get' call, Eli Zaretskii, 2022/06/16
- master b3cbcebd9a 8/9: Speed up Org to Texinfo generation, Eli Zaretskii, 2022/06/16