]> git.eshelyaron.com Git - emacs.git/commitdiff
should be faster
authorJoão Távora <joaotavora@gmail.com>
Mon, 16 Aug 2021 17:32:34 +0000 (18:32 +0100)
committerJoão Távora <joaotavora@gmail.com>
Mon, 16 Aug 2021 17:41:24 +0000 (18:41 +0100)
* lisp/minibuffer.el (completion--get-lazy-hilit-re):
(completion--flex-get-completion-score): New functions.
(completion--flex-adjust-metadata): Use
completion--flex-get-completion-score.
(completion-lazy-hilit): Use completion--get-lazy-hilit-re.

lisp/minibuffer.el

index b61620d1dc476cb2bbcee06aa1843ebd9b749ba1..2660c9d1a01de2bcf4ae6b8575f68cc23d790ad3 100644 (file)
@@ -3541,21 +3541,19 @@ and useless hint.  To author a completion style that takes
 advantage of this, look in the source of
 `completion-pcm--hilit-commonality' for ideas.")
 
-(defvar completion--get-lazy-highlight-cache
+(defvar completion--lazy-highlight-cache
   (make-hash-table :weakness 'key))
 
+(defvar completion--score-map (make-hash-table :size (obarray-size obarray)))
+
 (defun completion--get-lazy-hilit-re ()
   "Helper for `completion-lazy-hilit'."
-  (let* ((data (gethash completion-lazy-hilit completion--get-lazy-highlight-cache))
-         (re (car data)))
-    re))
+  (gethash completion-lazy-hilit completion--lazy-highlight-cache))
 
 (defun completion--flex-get-completion-score (str)
   "Get the Flex completion score of STR"
   (if completion-lazy-hilit
-      (let* ((data (gethash completion-lazy-hilit completion--get-lazy-highlight-cache))
-             (score-ht (and data (cdr data))))
-        (or (gethash str score-ht) 0))
+      (gethash str completion--score-map)
       (get-text-property 0 'completion-score str)))
 
 (defun completion-lazy-hilit (str)
@@ -3563,7 +3561,7 @@ advantage of this, look in the source of
 See documentation for variable `completion-lazy-hilit' for more
 details."
   (let* ((str (copy-sequence str))
-         (re (and completion-lazy-hilit (completion--get-lazy-hilit-re)))
+         (re (completion--get-lazy-hilit-re))
          (md (and re (string-match re str) (cddr (match-data t))))
          (me (and md (match-end 0)))
          (from 0))
@@ -3574,8 +3572,6 @@ details."
       (add-face-text-property from me 'completions-common-part nil str))
     str))
 
-
-
 (defun completion-pcm--hilit-commonality (pattern completions)
   "Show where and how well PATTERN matches COMPLETIONS.
 PATTERN, a list of symbols and strings as seen
@@ -3588,14 +3584,11 @@ between 0 and 1, and with faces `completions-common-part',
     (let* ((re (completion-pcm--pattern->regex pattern 'group))
            (point-idx (completion-pcm--pattern-point-idx pattern))
            (case-fold-search completion-ignore-case)
-           score-ht
            last-md)
       (when completion-lazy-hilit
         (puthash completion-lazy-hilit
-                 (cons re (setq score-ht
-                                (make-hash-table
-                                 :size (length completions))))
-                 completion--get-lazy-highlight-cache))
+                 re
+                 completion--lazy-highlight-cache))
       (mapcar
        (lambda (str)
          (unless completion-lazy-hilit
@@ -3683,8 +3676,7 @@ between 0 and 1, and with faces `completions-common-part',
                 nil str))
            (let ((score (/ score-numerator (* end (1+ score-denominator)) 1.0)))
              (unless (zerop (length str))
-               (if completion-lazy-hilit
-                   (puthash str score score-ht)
+               (if completion-lazy-hilit (puthash str score completion--score-map)
                  (put-text-property 0 1 'completion-score score str)))))
          str)
        completions))))