From fa047a52c0d40aace236bd56f1d8ca70935f438a Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 5 Jul 2024 18:53:36 +0800 Subject: [PATCH] Improve `tab-line-tabs-fixed-window-buffers` sorting performance * lsp/tab-line.el (tab-line-tabs-fixed-window-buffers): Enhanced `tab-line-tabs-fixed-window-buffers` performance by optimizing buffer sorting mechanism. Replaced inefficient `seq-position` calls with a hash table to cache buffer positions, significantly improving speed when handling large buffer lists. --- lisp/tab-line.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lisp/tab-line.el b/lisp/tab-line.el index 1d14fda9825..e4908c61542 100644 --- a/lisp/tab-line.el +++ b/lisp/tab-line.el @@ -555,10 +555,14 @@ This means that switching to a buffer previously shown in the same window will keep the same order of tabs that was before switching. And newly displayed buffers are added to the end of the tab line." (let* ((old-buffers (window-parameter nil 'tab-line-buffers)) + (buffer-positions (let ((index-table (make-hash-table :test 'eq))) + (seq-do-indexed + (lambda (buf idx) (puthash buf idx index-table)) + old-buffers) + index-table)) (new-buffers (sort (tab-line-tabs-window-buffers) :key (lambda (buffer) - (or (seq-position old-buffers buffer) - most-positive-fixnum))))) + (gethash buffer buffer-positions most-positive-fixnum))))) (set-window-parameter nil 'tab-line-buffers new-buffers) new-buffers)) -- 2.44.1