Browse Source

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'.
Ihor Radchenko 2 năm trước cách đây
mục cha
commit
e9bd219e35
1 tập tin đã thay đổi với 6 bổ sung7 xóa
  1. 6 7
      lisp/org-element.el

+ 6 - 7
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)))