]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve 'tab-line-tabs-fixed-window-buffers' sorting performance
authorEval EXEC <execvy@gmail.com>
Fri, 5 Jul 2024 10:53:36 +0000 (18:53 +0800)
committerEshel Yaron <me@eshelyaron.com>
Mon, 8 Jul 2024 20:58:22 +0000 (22:58 +0200)
* 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
(cherry picked from commit fffab032b05d5dcb72d6729321739ca814c54a28)

lisp/tab-line.el

index 1d14fda9825dd40ed4fadb34f482db7daed8ce3d..462a0a27692e2bd9a76f17c454344198979536d8 100644 (file)
@@ -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.
 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))