aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2025-07-10 09:40:51 +0300
committerJuri Linkov2025-07-10 09:40:51 +0300
commit99080d0c04931b5d45026e1ee44526bbbb8dfdef (patch)
treefc036ac14e8de3bd8848073ee65826a694e36962
parentb85d9048f4a32c7c50894e991423d021d9f95317 (diff)
downloademacs-99080d0c04931b5d45026e1ee44526bbbb8dfdef.tar.gz
emacs-99080d0c04931b5d45026e1ee44526bbbb8dfdef.zip
Cache only the last string in 'tab-bar-format-align-right' (bug#78953)
* lisp/tab-bar.el (tab-bar--align-right-cache): Rename from 'tab-bar--align-right-hash'. (tab-bar-format-align-right): Use it to store the string in the car, and the width in the cdr.
-rw-r--r--lisp/tab-bar.el19
1 files changed, 9 insertions, 10 deletions
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 53da087384d..396658af640 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -1194,8 +1194,8 @@ when the tab is current. Return the result as a keymap."
1194 `((add-tab menu-item ,tab-bar-new-button tab-bar-new-tab 1194 `((add-tab menu-item ,tab-bar-new-button tab-bar-new-tab
1195 :help "New tab")))) 1195 :help "New tab"))))
1196 1196
1197(defvar tab-bar--align-right-hash nil 1197(defvar tab-bar--align-right-cache nil
1198 "Memoization table for `tab-bar-format-align-right'.") 1198 "Optimization for `tab-bar-format-align-right'.")
1199 1199
1200(defun tab-bar-format-align-right (&optional rest) 1200(defun tab-bar-format-align-right (&optional rest)
1201 "Align the rest of tab bar items to the right. 1201 "Align the rest of tab bar items to the right.
@@ -1203,20 +1203,19 @@ The argument `rest' is used for special handling of this item
1203by `tab-bar-format-list' that collects the rest of formatted items. 1203by `tab-bar-format-list' that collects the rest of formatted items.
1204This prevents calling other non-idempotent items like 1204This prevents calling other non-idempotent items like
1205`tab-bar-format-global' twice." 1205`tab-bar-format-global' twice."
1206 (unless tab-bar--align-right-hash
1207 (define-hash-table-test 'tab-bar--align-right-hash-test
1208 #'equal-including-properties
1209 #'sxhash-equal-including-properties)
1210 (setq tab-bar--align-right-hash
1211 (make-hash-table :test 'tab-bar--align-right-hash-test)))
1212 (let* ((rest (or rest (tab-bar-format-list 1206 (let* ((rest (or rest (tab-bar-format-list
1213 (cdr (memq 'tab-bar-format-align-right 1207 (cdr (memq 'tab-bar-format-align-right
1214 tab-bar-format))))) 1208 tab-bar-format)))))
1215 (rest (mapconcat (lambda (item) (nth 2 item)) rest "")) 1209 (rest (mapconcat (lambda (item) (nth 2 item)) rest ""))
1216 (hpos (progn 1210 (hpos (progn
1217 (add-face-text-property 0 (length rest) 'tab-bar t rest) 1211 (add-face-text-property 0 (length rest) 'tab-bar t rest)
1218 (with-memoization (gethash rest tab-bar--align-right-hash) 1212 (or (and tab-bar--align-right-cache
1219 (string-pixel-width rest)))) 1213 (equal-including-properties
1214 (car tab-bar--align-right-cache) rest)
1215 (cdr tab-bar--align-right-cache))
1216 (let ((width (string-pixel-width rest)))
1217 (setq tab-bar--align-right-cache (cons rest width))
1218 width))))
1220 (str (propertize " " 'display 1219 (str (propertize " " 'display
1221 ;; The `right' spec doesn't work on TTY frames 1220 ;; The `right' spec doesn't work on TTY frames
1222 ;; when windows are split horizontally (bug#59620) 1221 ;; when windows are split horizontally (bug#59620)