branch: externals/corfu
commit 13fb95fa998f50fc9a810fb9fcbcd77538d8971f
Author: Daniel Mendler <m...@daniel-mendler.de>
Commit: Daniel Mendler <m...@daniel-mendler.de>

    Improve corfu-history--sort
---
 extensions/corfu-history.el | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/extensions/corfu-history.el b/extensions/corfu-history.el
index 0012d6f9c9..d0821bc2d0 100644
--- a/extensions/corfu-history.el
+++ b/extensions/corfu-history.el
@@ -58,12 +58,13 @@ or the property `history-length' of `corfu-history'.")
 (defun corfu-history--sort (cands)
   "Sort CANDS by history."
   (unless corfu-history--hash
-    (setq corfu-history--hash (make-hash-table :test #'equal :size (length 
corfu-history)))
-    (cl-loop for elem in corfu-history for index from 0 do
-             (unless (gethash elem corfu-history--hash)
-               (puthash elem index corfu-history--hash))))
-  (cl-loop for max = most-positive-fixnum for cand on cands do
-           (setcar cand (cons (car cand) (gethash (car cand) 
corfu-history--hash max))))
+    (let ((ht (make-hash-table :test #'equal :size (length corfu-history))))
+      (cl-loop for elem in corfu-history for index from 0 do
+               (unless (gethash elem ht) (puthash elem index ht)))
+      (setq corfu-history--hash ht)))
+  (cl-loop for ht = corfu-history--hash for max = most-positive-fixnum
+           for cand on cands do
+           (setcar cand (cons (car cand) (gethash (car cand) ht max))))
   (setq cands (sort cands #'corfu-history--sort-predicate))
   (cl-loop for cand on cands do (setcar cand (caar cand)))
   cands)

Reply via email to