From d2fc4be73b99a21add1a209691218dcd8a3c59e9 Mon Sep 17 00:00:00 2001 From: Samuel Culpepper Date: Thu, 30 Sep 2021 12:54:25 +0200 Subject: [PATCH] optimize(core) linear->constant time filter-fn (#1876) in org-roam-node-read, there is no need to check filter-fn for each node, move the branch up, O(n) to O(1) --- org-roam-node.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/org-roam-node.el b/org-roam-node.el index 08ffceb..938ad59 100644 --- a/org-roam-node.el +++ b/org-roam-node.el @@ -441,8 +441,10 @@ SORT-FN is a function to sort nodes. See `org-roam-node-read-sort-by-file-mtime' for an example sort function. If REQUIRE-MATCH, the minibuffer prompt will require a match." (let* ((nodes (org-roam-node-read--completions)) - (nodes (cl-remove-if-not (lambda (n) - (if filter-fn (funcall filter-fn (cdr n)) t)) nodes)) + (nodes (if filter-fn + (cl-remove-if-not + (lambda (n) (funcall filter-fn (cdr n)) t)) + nodes)) (sort-fn (or sort-fn (when org-roam-node-default-sort (intern (concat "org-roam-node-read-sort-by-"