Change: (children, descendants) Return after finding one match

A simple optimization that can be significant in large subtrees.
This commit is contained in:
Adam Porter 2019-08-30 09:32:03 -05:00
parent e839397579
commit 802bc462d6

View file

@ -661,8 +661,12 @@ Or, when possible, fix the problem."
(funcall ,query))) (funcall ,query)))
(t `(and (level ,level) (t `(and (level ,level)
,query))))) ,query)))))
(catch 'found
(org-ql-select (current-buffer) (org-ql-select (current-buffer)
query :narrow t :action (lambda () t))))))) query
:narrow t
:action (lambda ()
(throw 'found t)))))))))
(org-ql--defpred descendants (query) (org-ql--defpred descendants (query)
"Return non-nil if current entry has descendants matching QUERY." "Return non-nil if current entry has descendants matching QUERY."
@ -670,8 +674,12 @@ Or, when possible, fix the problem."
(save-restriction (save-restriction
(org-narrow-to-subtree) (org-narrow-to-subtree)
(when (org-goto-first-child) (when (org-goto-first-child)
(catch 'found
(org-ql-select (current-buffer) (org-ql-select (current-buffer)
query :narrow t :action (lambda () t)))))) query
:narrow t
:action (lambda ()
(throw 'found t))))))))
(org-ql--defpred category (&rest categories) (org-ql--defpred category (&rest categories)
"Return non-nil if current heading is in one or more of CATEGORIES (a list of strings)." "Return non-nil if current heading is in one or more of CATEGORIES (a list of strings)."