Skip to content

Commit

Permalink
org-element--cache-active-p: Improve performance
Browse files Browse the repository at this point in the history
* lisp/org-element.el (org-element--cache-active-p): Remove expensive
`derived-mode-p' call.  Reshuffle the conditions to avoid costly
`memq' call as much as possible.  Inline the function.
  • Loading branch information
yantar92 committed Sep 21, 2022
1 parent f1a1974 commit 7e9d927
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lisp/org-element.el
Original file line number Diff line number Diff line change
Expand Up @@ -5679,12 +5679,12 @@ This function assumes `org-element--headline-cache' is a valid AVL tree."

;;;; Tools

(defun org-element--cache-active-p (&optional called-from-cache-change-func-p)
(defsubst org-element--cache-active-p (&optional called-from-cache-change-func-p)
"Non-nil when cache is active in current buffer."
(and org-element-use-cache
org-element--cache
(derived-mode-p 'org-mode)
(or called-from-cache-change-func-p
(eq org-element--cache-change-tic (buffer-chars-modified-tick))
(and
;; org-num-mode calls some Org structure analysis functions
;; that can trigger cache update in the middle of changes. See
Expand All @@ -5699,8 +5699,7 @@ This function assumes `org-element--headline-cache' is a valid AVL tree."
;; `combine-change-calls' because the buffer is potentially
;; changed without notice (the change will be registered
;; after exiting the `combine-change-calls' body though).
(memq #'org-element--cache-after-change after-change-functions))
(eq org-element--cache-change-tic (buffer-chars-modified-tick)))))
(memq #'org-element--cache-after-change after-change-functions)))))

;; FIXME: Remove after we establish that hashing is effective.
(defun org-element-cache-hash-show-statistics ()
Expand Down

0 comments on commit 7e9d927

Please sign in to comment.