[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/vertico e8a3e96 16/48: Minor optimization
From: |
Stefan Monnier |
Subject: |
[elpa] externals/vertico e8a3e96 16/48: Minor optimization |
Date: |
Mon, 5 Apr 2021 10:54:41 -0400 (EDT) |
branch: externals/vertico
commit e8a3e965bdb781b96f9bfbfd5205379af0ffd567
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Minor optimization
---
minicomp.el | 56 +++++++++++++++++++++++++++++++++-----------------------
1 file changed, 33 insertions(+), 23 deletions(-)
diff --git a/minicomp.el b/minicomp.el
index 98c1ca6..5e6597e 100644
--- a/minicomp.el
+++ b/minicomp.el
@@ -128,33 +128,43 @@
;; Store the history position first in a hashtable in order to allow O(1)
history lookup. File
;; names get special treatment. In principle, completion tables with
boundaries should also get
;; special treatment, but files are the most important.
- (let ((index 0)
- ;; History disabled if `minibuffer-history-variable' eq `t'.
- (hist (and (not (eq minibuffer-history-variable t))
- (symbol-value minibuffer-history-variable))))
- (if (eq minibuffer-history-variable 'file-name-history)
- (let* ((dir (expand-file-name (substitute-in-file-name
- (or (file-name-directory input)
- default-directory))))
- (adir (abbreviate-file-name dir)))
- (unless (equal minicomp--history-dir dir)
- (setq minicomp--history-hash (make-hash-table :test #'equal :size
(length hist))
- minicomp--history-dir dir)
- (dolist (elem hist)
- (when-let (file (cond
- ((string-prefix-p dir elem) (substring elem
(length dir)))
- ((string-prefix-p adir elem) (substring elem
(length adir)))))
+ (cond
+ ((eq minibuffer-history-variable 'file-name-history)
+ (let ((dir (expand-file-name (substitute-in-file-name
+ (or (file-name-directory input)
+ default-directory)))))
+ (unless (equal minicomp--history-dir dir)
+ (setq minicomp--history-hash (make-hash-table :test #'equal :size
(length file-name-history))
+ minicomp--history-dir dir)
+ (let* ((index 0)
+ (adir (abbreviate-file-name dir))
+ (dlen (length dir))
+ (alen (length adir)))
+ (dolist (elem file-name-history)
+ (let* ((len (length elem))
+ (file (cond
+ ((and (> len dlen)
+ (eq t (compare-strings dir 0 dlen elem 0
dlen)))
+ (substring elem dlen))
+ ((and (> len alen)
+ (eq t (compare-strings adir 0 alen elem 0
alen)))
+ (substring elem alen)))))
+ (when file
(when-let (slash (string-match-p "/" file))
(setq file (substring file 0 (1+ slash))))
(unless (gethash file minicomp--history-hash)
(puthash file index minicomp--history-hash)))
- (setq index (1+ index)))))
- (unless minicomp--history-hash
- (setq minicomp--history-hash (make-hash-table :test #'equal :size
(length hist)))
- (dolist (elem hist)
- (unless (gethash elem minicomp--history-hash)
- (puthash elem index minicomp--history-hash))
- (setq index (1+ index))))))
+ (setq index (1+ index))))))))
+ ((not minicomp--history-hash)
+ (let ((index 0)
+ ;; History disabled if `minibuffer-history-variable' eq `t'.
+ (hist (and (not (eq minibuffer-history-variable t))
+ (symbol-value minibuffer-history-variable))))
+ (setq minicomp--history-hash (make-hash-table :test #'equal :size
(length hist)))
+ (dolist (elem hist)
+ (unless (gethash elem minicomp--history-hash)
+ (puthash elem index minicomp--history-hash))
+ (setq index (1+ index))))))
;; Decorate each candidate with (index<<13) + length. This way we sort first
by index and then by
;; length. We assume that the candidates are shorter than 2**13 characters
and that the history is
;; shorter than 2**16 entries.
- [elpa] externals/vertico f132f1b 10/48: improve prompt selection, add minicomp--goto, (continued)
- [elpa] externals/vertico f132f1b 10/48: improve prompt selection, add minicomp--goto, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico 9b81d8d 08/48: remove ./ and ../ from file completion candidates, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico 5bbddb0 03/48: add while-no-input-ignore-events, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico 4ce7c8d 11/48: use seq-subseq, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico f558f53 04/48: extract minicomp--pred, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico 9db7c78 20/48: add minicomp-count-format, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico 245944a 21/48: remap previous/next-line, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico 7fbaeaf 15/48: Add sorting by history for files, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico c2bfea2 17/48: use candidate returned from affixation function, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico bafee15 19/48: add minicomp-exit-input, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico e8a3e96 16/48: Minor optimization,
Stefan Monnier <=
- [elpa] externals/vertico 333a0a2 29/48: use chunks for candidate formatting, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico 8b760bc 30/48: Fix minicomp--index initialization, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico ed87a60 33/48: Require 27.1, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico c4b3e8b 42/48: Simplify minicomp--flatten-prop, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico 99a355c 12/48: abort minibuffer session if while-no-input returns nil, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico f835fb6 14/48: add readme, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico 1b75916 18/48: better orderless integration, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico 42823ce 25/48: Use read-char-exclusive to avoid error message, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico af41b13 24/48: fix lexical scoping, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico fa9e8dc 26/48: split functions, Stefan Monnier, 2021/04/05