emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org 0551eba40c 05/13: org-export-get-ordinal: Cache res


From: ELPA Syncer
Subject: [elpa] externals/org 0551eba40c 05/13: org-export-get-ordinal: Cache results
Date: Fri, 7 Oct 2022 01:57:50 -0400 (EDT)

branch: externals/org
commit 0551eba40ca1cdeac8645c8614747566025a7e94
Author: Ihor Radchenko <yantar92@gmail.com>
Commit: Ihor Radchenko <yantar92@gmail.com>

    org-export-get-ordinal: Cache results
    
    * lisp/ox.el (org-export-get-ordinal): Cache results while counting to
    avoid quadratic scaling.
    
    Reported-by: Rudolf Adamkovič <salutis@me.com>
    Link: https://list.orgmode.org/m2zgef774u.fsf@me.com/T/#t
---
 lisp/ox.el | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/lisp/ox.el b/lisp/ox.el
index ec5c305487..3e53692dc6 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -4679,10 +4679,22 @@ objects of the same type."
        (org-element-map (plist-get info :parse-tree)
           (or types (org-element-type element))
         (lambda (el)
-          (cond
-           ((eq element el) (1+ counter))
-           ((not predicate) (cl-incf counter) nil)
-           ((funcall predicate el info) (cl-incf counter) nil)))
+           (let ((cached (org-element-property :org-export--counter el)))
+            (cond
+             ((eq element el) (1+ counter))
+              ;; Use cached result.
+              ((and cached (equal predicate (car cached)))
+               (cdr cached))
+             ((not predicate)
+               (cl-incf counter)
+               (org-element-put-property
+                el :org-export--counter (cons predicate counter))
+               nil)
+             ((funcall predicate el info)
+               (cl-incf counter)
+               (org-element-put-property
+                el :org-export--counter (cons predicate counter))
+               nil))))
         info 'first-match)))))
 
 ;;;; For Raw objects



reply via email to

[Prev in Thread] Current Thread [Next in Thread]