emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ivy 738da36d1b 2/3: Less consing in ivy--re-filter


From: Basil L. Contovounesios
Subject: [elpa] externals/ivy 738da36d1b 2/3: Less consing in ivy--re-filter
Date: Fri, 17 May 2024 07:17:33 -0400 (EDT)

branch: externals/ivy
commit 738da36d1b61e5b2a38e5775b23edd214ad88d6e
Author: Basil L. Contovounesios <basil@contovou.net>
Commit: Basil L. Contovounesios <basil@contovou.net>

    Less consing in ivy--re-filter
    
    Avoid repeated cl-remove when matching multiple regexps;
    unconditionally make a copy and use cl-delete instead.  This
    slightly penalizes the case where no candidates are removed.
    
    Using cl-remove for the first pass and subsequently switching to
    cl-delete would not always work, since it's unknown whether and when
    cl-remove returns a full or partial copy of its input list.
    
    Yet another option would be to consolidate all regexps AOT, in the
    hope that regexp backtracking in C is faster than looping in Lisp,
    but that would involve more work both for the programmer and in
    terms of consing.  I'm also not certain about the Ivy semantics for
    numbered match groups, for matches that are kept.
    
    * ivy.el (ivy--re-filter): Replace potentially repeated cl-remove
    with unconditional copy-sequence followed by cl-delete.  This
    produces less garbage in pathological cases.
---
 ivy.el | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/ivy.el b/ivy.el
index db41371913..446f57e77d 100644
--- a/ivy.el
+++ b/ivy.el
@@ -3604,8 +3604,8 @@ In any Ivy completion session, the case folding starts 
with
 RE is a list of cons cells, with a regexp car and a boolean cdr.
 When the cdr is t, the car must match.
 Otherwise, the car must not match."
-  (if (equal re "")
-      candidates
+  (unless (member re '("" ()))
+    (setq candidates (copy-sequence candidates))
     (ignore-errors
       (dolist (re (if (stringp re) (list (cons re t)) re))
         (let* ((re-str (car re))
@@ -3614,10 +3614,10 @@ Otherwise, the car must not match."
                     (funcall mkpred re-str)
                   (lambda (x) (string-match-p re-str x)))))
           (setq candidates
-                (cl-remove nil candidates
+                (cl-delete nil candidates
                            (if (cdr re) :if-not :if)
-                           pred))))
-      candidates)))
+                           pred))))))
+  candidates)
 
 (defun ivy--filter (name candidates)
   "Return all items that match NAME in CANDIDATES.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]