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

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

[elpa] externals/vertico 39418855cd: Use more efficient string flattenin


From: ELPA Syncer
Subject: [elpa] externals/vertico 39418855cd: Use more efficient string flattening which allocates less
Date: Tue, 28 Dec 2021 17:58:12 -0500 (EST)

branch: externals/vertico
commit 39418855cd2294483266b81ed9e8a6904c0591f5
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    Use more efficient string flattening which allocates less
    
    The function vertico--display-string is derived from consult--display-width 
and
    embark--display-width. @oantolin recently introduced the same function in 
Embark
    (embark--for-display).
---
 vertico.el | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/vertico.el b/vertico.el
index 35be6a5586..f67df0104b 100644
--- a/vertico.el
+++ b/vertico.el
@@ -456,19 +456,21 @@ The function is configured by BY, BSIZE, BINDEX, BPRED 
and PRED."
                                              minibuffer-completion-predicate)))
                    -1 0)))))))
 
-(defun vertico--flatten-string (prop str)
-  "Flatten STR with display or invisible PROP."
-  (let ((end (length str)) (pos 0) (chunks))
+(defun vertico--display-string (str)
+  "Return display STR without display and invisible properties."
+  (let ((end (length str)) (pos 0) chunks)
     (while (< pos end)
-      (let ((next (next-single-property-change pos prop str end))
-            (val (get-text-property pos prop str)))
-        (cond
-         ((and val (eq prop 'display) (stringp val))
-          (push val chunks))
-         ((not (and val (eq prop 'invisible)))
-          (push (substring str pos next) chunks)))
-        (setq pos next)))
-    (apply #'concat (nreverse chunks))))
+      (let ((nextd (next-single-property-change pos 'display str end))
+            (display (get-text-property pos 'display str)))
+        (if (stringp display)
+            (progn (push display chunks) (setq pos nextd))
+          (while (< pos nextd)
+            (let ((nexti (next-single-property-change pos 'invisible str 
nextd)))
+              (unless (get-text-property pos 'invisible str)
+                (unless (and (= pos 0) (= nexti end)) ;; full string -> avoid 
allocation
+                  (push (substring str pos nexti) chunks)))
+              (setq pos nexti))))))
+    (if chunks (apply #'concat (nreverse chunks)) str)))
 
 (defun vertico--truncate-multiline (cand max-width)
   "Truncate multiline CAND to MAX-WIDTH."
@@ -481,8 +483,7 @@ The function is configured by BY, BSIZE, BINDEX, BPRED and 
PRED."
 
 (defun vertico--format-candidate (cand prefix suffix index _start)
   "Format CAND given PREFIX, SUFFIX and INDEX."
-  (setq cand (concat prefix cand suffix "\n")
-        cand (vertico--flatten-string 'invisible (vertico--flatten-string 
'display cand)))
+  (setq cand (vertico--display-string (concat prefix cand suffix "\n")))
   (when (= index vertico--index)
     (add-face-text-property 0 (length cand) 'vertico-current 'append cand))
   cand)
@@ -498,10 +499,9 @@ The function is configured by BY, BSIZE, BINDEX, BPRED and 
PRED."
 (defun vertico--arrange-candidates ()
   "Arrange candidates."
   (vertico--update-scroll)
-  (let ((curr-line 0) (lines))
+  (let ((curr-line 0) lines)
     ;; Compute group titles
-    (let* ((index vertico--scroll)
-           (title)
+    (let* (title (index vertico--scroll)
            (group-fun (vertico--metadata-get 'group-function))
            (group-format (and group-fun vertico-group-format (concat 
vertico-group-format "\n")))
            (candidates



reply via email to

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