From 1620faf160c322b6b8f300816c8603fe5b40e677 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Fri, 27 Oct 2023 17:29:16 +0100 Subject: [PATCH] Revert most of "Optimize flex completion style a bit more" The performace optimization introduces problems and isn't worth it. The refactorings into separate functions are useful, though. bug#48841, bug#47711 --- lisp/minibuffer.el | 55 ++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index b38eb49aba8..cd8eeee2c78 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -3721,33 +3721,21 @@ PATTERN is as returned by `completion-pcm--string->pattern'." ;; Use all-completions to do an initial cull. This is a big win, ;; since all-completions is written in C! - (let* ((case-fold-search completion-ignore-case) - (completion-regexp-list (cons - ;; Convert search pattern to a - ;; standard regular expression. - (completion-pcm--pattern->regex pattern) - completion-regexp-list)) - (completions (all-completions - (concat prefix - (if (stringp (car pattern)) (car pattern) "")) - table pred))) - (cond ((or (not (functionp table)) - (cl-loop for e in pattern never (stringp e))) - ;; The internal functions already obeyed completion-regexp-list. - completions) - (t - ;; The pattern has something interesting to match, in - ;; which case we take the opportunity to add an early - ;; completion-score cookie to each completion. - (cl-loop with re = (completion-pcm--pattern->regex pattern 'group) - for orig in completions - for comp = (copy-sequence orig) - for score = (completion--flex-score comp re t) - when score - do (put-text-property 0 1 'completion-score - score - comp) - and collect comp)))))) + (let* (;; Convert search pattern to a standard regular expression. + (regex (completion-pcm--pattern->regex pattern)) + (case-fold-search completion-ignore-case) + (completion-regexp-list (cons regex completion-regexp-list)) + (compl (all-completions + (concat prefix + (if (stringp (car pattern)) (car pattern) "")) + table pred))) + (if (not (functionp table)) + ;; The internal functions already obeyed completion-regexp-list. + compl + (let ((poss ())) + (dolist (c compl) + (when (string-match-p regex c) (push c poss))) + (nreverse poss)))))) (defvar flex-score-match-tightness 3 "Controls how the `flex' completion style scores its matches. @@ -3934,20 +3922,19 @@ highlighting." (cond ((and completions (cl-loop for e in pattern thereis (stringp e))) (let* ((re (completion-pcm--pattern->regex pattern 'group)) - (score-maybe (lambda (str) - (unless (get-text-property 0 'completion-score str) - (put-text-property 0 1 'completion-score - (completion--flex-score str re) - str))))) + (score (lambda (str) + (put-text-property 0 1 'completion-score + (completion--flex-score str re) + str)))) (cond (completion-lazy-hilit (setq completion-lazy-hilit-fn (lambda (str) (completion--hilit-from-re str re))) - (mapc score-maybe completions)) + (mapc score completions)) (t (mapcar (lambda (str) (setq str (copy-sequence str)) - (funcall score-maybe str) + (funcall score str) (completion--hilit-from-re str re) str) completions))))) -- 2.39.2