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'.
This commit is contained in:
Ihor Radchenko 2022-09-21 12:23:57 +08:00
parent 7e9d927298
commit e9bd219e35
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 6 additions and 7 deletions

View File

@ -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)))