Improve 'tab-line-tabs-fixed-window-buffers' sorting performance
* lsp/tab-line.el (tab-line-tabs-fixed-window-buffers): Enhance 'tab-line-tabs-fixed-window-buffers' performance by optimizing buffer sorting mechanism. Replace inefficient 'seq-position' calls with a hash table to cache buffer positions, significantly improving speed when handling large buffer lists (bug#71958). Copyright-paperwork-exempt: yes
This commit is contained in:
parent
069fa63909
commit
fffab032b0
1 changed files with 7 additions and 2 deletions
|
@ -555,10 +555,15 @@ This means that switching to a buffer previously shown in the same
|
||||||
window will keep the same order of tabs that was before switching.
|
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."
|
And newly displayed buffers are added to the end of the tab line."
|
||||||
(let* ((old-buffers (window-parameter nil 'tab-line-buffers))
|
(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)
|
(new-buffers (sort (tab-line-tabs-window-buffers)
|
||||||
:key (lambda (buffer)
|
:key (lambda (buffer)
|
||||||
(or (seq-position old-buffers buffer)
|
(gethash buffer buffer-positions
|
||||||
most-positive-fixnum)))))
|
most-positive-fixnum)))))
|
||||||
(set-window-parameter nil 'tab-line-buffers new-buffers)
|
(set-window-parameter nil 'tab-line-buffers new-buffers)
|
||||||
new-buffers))
|
new-buffers))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue