From e9bd219e35090a80833834bbee97124ad9320f64 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Wed, 21 Sep 2022 12:23:57 +0800 Subject: [PATCH] org-element--cache-verify-element: Improve performance * lisp/org-element.el: Remove unconditional checks when verification is disabled. Do not call costly `derived-mode-p' and unnecessary `org-element-property'. --- lisp/org-element.el | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index 72a20b6ce..53d127561 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -7094,11 +7094,6 @@ change, as an integer." "Verify correctness of ELEMENT when `org-element--cache-self-verify' is non-nil. Return non-nil when verification failed." - ;; Verify correct parent for the element. - (unless (or (org-element-property :parent element) - (eq 'org-data (org-element-type element))) - (org-element--cache-warn "Got element without parent (cache active?: %S). Please report it to Org mode mailing list (M-x org-submit-bug-report).\n%S" (org-element--cache-active-p) element) - (org-element-cache-reset)) (let ((org-element--cache-self-verify (or org-element--cache-self-verify (and (boundp 'org-batch-test) org-batch-test))) @@ -7106,10 +7101,14 @@ Return non-nil when verification failed." (if (and (boundp 'org-batch-test) org-batch-test) 1 org-element--cache-self-verify-frequency))) + ;; Verify correct parent for the element. + (unless (or (not org-element--cache-self-verify) + (org-element-property :parent element) + (eq 'org-data (org-element-type element))) + (org-element--cache-warn "Got element without parent (cache active?: %S). Please report it to Org mode mailing list (M-x org-submit-bug-report).\n%S" (org-element--cache-active-p) element) + (org-element-cache-reset)) (when (and org-element--cache-self-verify (org-element--cache-active-p) - (derived-mode-p 'org-mode) - (org-element-property :parent element) (eq 'headline (org-element-type element)) ;; Avoid too much slowdown (< (random 1000) (* 1000 org-element--cache-self-verify-frequency)))