From 802bc462d6594b460fd0d4d7723094c8b7b53a03 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Fri, 30 Aug 2019 09:32:03 -0500 Subject: [PATCH] Change: (children, descendants) Return after finding one match A simple optimization that can be significant in large subtrees. --- org-ql.el | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/org-ql.el b/org-ql.el index 7e80e17..885b7f5 100644 --- a/org-ql.el +++ b/org-ql.el @@ -661,8 +661,12 @@ Or, when possible, fix the problem." (funcall ,query))) (t `(and (level ,level) ,query))))) - (org-ql-select (current-buffer) - query :narrow t :action (lambda () t))))))) + (catch 'found + (org-ql-select (current-buffer) + query + :narrow t + :action (lambda () + (throw 'found t))))))))) (org-ql--defpred descendants (query) "Return non-nil if current entry has descendants matching QUERY." @@ -670,8 +674,12 @@ Or, when possible, fix the problem." (save-restriction (org-narrow-to-subtree) (when (org-goto-first-child) - (org-ql-select (current-buffer) - query :narrow t :action (lambda () t)))))) + (catch 'found + (org-ql-select (current-buffer) + query + :narrow t + :action (lambda () + (throw 'found t)))))))) (org-ql--defpred category (&rest categories) "Return non-nil if current heading is in one or more of CATEGORIES (a list of strings)."